Several things contribute to beer’s microbiological stability.
Alcohol content. Most bugs don’t react well with ethanol
Low pH. The pH of finished beer is usually just above 4, so fairly acidic.
Hops. Hops do more than just flavor the beer, they have compounds that are fairly bacteriostatic, especially against gram-positive bacteria.
These three things together make beer an unfavorable place for most bacteria, and most of those that can survive are ones that we call “non beer spoilers”, in other words they do not have a marked effect on the flavor or body.
Beer is one of the safest things you can drink, no known human pathogens can survive in beer. So when in doubt of the local water supply, drink beer.
One of the reasons we have lager beer, and Oktoberfest, is because the Germans figured out back in the day that if they tried to brew beer in the summer, it was nasty. So, as part of the german brewing law, they outlawed brewing in the summertime, which made the fall kind of suck. So, they came up with a way to brew a stronger beer with a time-, alcohol-, and cold-tolerant yeast (which is a really, really good trick if you haven’t invented microbiology yet…), and they stored the vats of slowly-fermenting beer in ice caves to ferment throughout the spring and summer.
So, they had beer that would last for at least six months in the keg.
However, until the past couple hundred years and the advent of bottles rather than wooden kegs, beer was usually pretty darn flat.
Trying to brew lagers in the summer before the days of commercial refrigeration would indeed have been a futile task, but I don’t think that all brewing was outlawed during the summer in Germany. Weissbiers have been made since the late 15th century and they use a top-fermenting yeast and warmer temperatures for fermentation. I have not heard that they were only brewed from fall - spring.
Actually someone does. In his book “A History of the World in Six Glasses” (If you like James Burke you’ll like this one) Tom Standage reproduces a few ancient claydrawings of beer drinking.
The ancient Mesopotamians are shown drinking beer through long straws…hollow reeds.There was no foam. There WAS garbage floating on top–grains and gunk that were used in the, um, brewing process. The hollow reeds cut through the garbage and got you to the Good Stuff.