I think it's absorbed into the bloodstream and then the flies don't like the 'garlicky tasting blood' and will fly off and find the next victim. I could have it all wrong though :-/
Garlic is a member of the onion family, onions can have a toxic effect on horses. You couldn't pay me to give garlic to my horses.
However, I used to have a ponies off the moors and mountains, and they would reek of garlic in season, whether they were self dosing, just ate the tops or what I don't know, but they did eat it, probably only small amounts though.