Today, the whole lime in Mexican beer thing is an asinine gimmick, thanks to the marketing behind beers like Corona.
In Mexico, adding a lime wedge to a beer is very much a touristy thing to do, a joke amongst locals. Hell, pairing any kind of fruit garnish with beer is something to joke about. That said, it does cut the sweet corn adjunct flavor or blandness of many of these beers, making them much more palatable, but at the same time, it doesn't say much for the beer if it needs a lime wedge.
Why a lime?
We decided to dig up some history on this citric custom, and here is what we found: One source notes that cans of beer were stored in dusty conditions and that a wedge of lime was ideal for cleaning the mouth of the can. Another states that early Mexican beer bottles were capped with linerless caps (that seal inside caps), which would leave a ring of rust on the bottle rim, and again, a wedge of lime cleaned it right up.
Even your insinuation that Mexico is bug infested, hence the idea of laying a lime wedge over the opening to keep out the flies, also holds some truth. There is even mentions of salt being added. Think tequila and all of this makes sense.
As tequila is the national drink of Mexico, limes would've been very accessible and no doubt would've added a refreshing edge to what would otherwise be a bland-ass brew. So it's only natural that limes would eventually be used with beer.
http://www.beeradvocate.com/news/stories_read/577