Yes, you can compost garlic – with a couple of warnings.
Firstly, garlic cloves/bulbs have a tendency to re-sprout if they are left whole. Chop them up first to avoid that – or don’t compost them, plant them out instead to grow more garlic bulbs or just “garlic greens” (the long leaves that sprout from the bulb).
Secondly, garlic is fine in a regular compost heap but in large quantities, it can cause problems in wormeries — like all strongly flavoured/spicy food, they’re not that keen on chomping through it, especially in the first few weeks. (Alliums, like onions and garlic, are bad for worms in large quantities – it’s not just that they don’t like garlic breath in case they run into other worms they fancy…)
Also see: How can I use up garlic bulbs? for ways to preserve garlic bulbs or use it in other ways