The effect garlic has on vampires in the buffyverse is one of mystery. The shows have referenced to it as an anti-vampire device more then once, ever since the first episode of Buffy, but they've never really said what it does.
It is mostly just shown as something to keep around to discourage vampires. Something they don't like. But what does it do exactly?
One idea is that because vampires have an enhanced sense of smell, they can't stand the smell of garlic. This theory has its problems though, for one, there are plenty of things that smell far worse then garlic. Even if vampires just didn't like garlic for some reason, garlic doesn't smell unless it's out of its clove, and especially when it's smashed. Most of the garlic in the show has all been in its clove.
Another idea is that perhaps it's an ingredient used in a spell that stops vampires. There is some evidence to this, but this doesn't explain all it's appearances on the shows.
The idea I think is most likely is that simply, when a vampire is around garlic, for whatever super natural reason, it, probably only slightly, weakens them. Perhaps it only throws a vampire off its game, or makes them feel uncomfortable. This would protect a household because a vampire would then move on to another house where it wouldn't feel the discomfort. It wouldn't be an effective device if the vampire has specifically targeted a house though, as they could overcome this discomfort if they wanted a certain target. This power is similar to that of a cross, a vampire fears a cross and can be pushed away by one, but they can overcome the fear if they really want to. It certainly isn't near as powerful as a cross though, and I highly doubt touching garlic would cause burning.
This is really the only idea I can think of that works well for everything, but maybe one day the show will reveal what it does exactly.