My 2 cents hypothesis : as some food “kills” many organism (garlic for exemple is an excellent gut cleaner), you also benefit to re-fill “good” organism like those in yoghurt.
I think you’d have to eat a colossal amount of garlic for its anti-microbial properties to have any measurable impact on your gut bacteria.
Garlic is both antimicrobial and a rich source of food (oligosaccharides) for many strains of gut bacteria. It happens to be a favorite additive to fermentation recipes for this reason.