You can keep roasted garlic in the fridge for up to 4 days before it starts to go bad.
Roasted garlic will keep in the refrigerator safely for up to 4 days and after 4 days the roasted garlic can start growing bacteria and will go bad.
If you have the roasted garlic in the fridge longer than 4 days then it's likely bad and should probably be thrown out.
You could keep the roasted garlic longer than 4 days by freezing the roasted garlic.
When you freeze the roasted garlic the freezing temperatures will keep bacteria away and the frozen roasted garlic will last in the freezer for 6 months to a year.
Although the roasted garlic will remain safe to eat after 6 months in the freezer the roasted garlic will lose it's freshness.
So it's best to eat the frozen roasted garlic within 6 months.