You can get some of the health benefits of garlic from taking garlic capsules but it's harder to get the allicin from the garlic capsules which is what provides the health benefits of garlic so you'd have to take more garlic pills to get the same health benefits of eating raw garlic.
To get the health benefits of raw garlic and get the allicin from garlic it's better to eat the raw garlic instead of taking garlic pills.