Well first off in very ancient times you wouldn't have much carbonation in beer at all because the clay jars that beer was kept in weren't airtight so carbonation would leak out just like the carbonation from a bottle of soda if you leave it with the top screwed on loosely. You can see pictures of ancient Egyptian beer jars here for example: https://blog.britishmuseum.org/a-sip-of-history-ancient-egyptian-beer/
But that doesn't mean that there wasn't any carbonation in ancient beer. In modern times brewers produce a large amount of beer and then ship it all over the world so you need something that was shelf stable. Of course you can't keep beer on hand forever but you can ship beer and have it sit on a store shelf for a while without anything terrible happening.
That wasn't how brewing was typically done in the ancient world. People very often brewed beer for an event. See here: Jennings, J., Antrobus, K., Atencio, S., Glavich, E., Johnson, R., Loffler, G., & Luu, C. (2005). “Drinking Beer in a Blissful Mood”: Alcohol Production, Operational Chains, and Feasting in the Ancient World. Current Anthropology, 46(2), 275-303.
This means that they'd try to get a large amount of alcohol together for a specific feast and brew that beer for that event. This means that it didn't matter if the beer would taste bad a week after the feast since there wouldn't BE any beer a week after the feast, it would all be drunk.
This removed one of the prime obstacles in pre-modern brewing: beer spoiling because of bacteria. After all if you brew the beer really fast and drink it all, you don't give bacteria time to make the beer really sour. Let's dig into that a bit.
In modern times hops do a good job of keeping bacteria out of the beer but before that there wasn't a good way to maintain sanitation so getting bacteria in the beer would be fairly common. However, in general terms yeast (the stuff that gives us alcohol and carbonation) reproduces in wort (unfermented beer) faster than bacteria but bacteria is a less picky eater. So if you have an infected batch of beer it'll taste fine initially (as the faster reproducing yeast predominate) but get more and more sour later on (as the bacteria eat up more and more of the starches that yeast have difficulty metabolizing and produce more and more acid). See for example here: Dierings, Leila Roseli, Braga, Cíntia Maia, Silva, Karolline Marques da, Wosiacki, Gilvan, & Nogueira, Alessandro. (2013). Population dynamics of mixed cultures of yeast and lactic acid bacteria in cider conditions. Brazilian Archives of Biology and Technology, 56(5), 837-847 for how bacteria predominates over yeast in the later periods of fermentation.
So if you're having a big feast coming up and you want to make sure that the beer won't be sour your best bet is to brew up the beer shortly before the feast so that any bacteria active won't have enough time to sour the beer AND because the beer isn't finished fermenting it'll still be pretty sweet which helps cover up any sourness AND because the beer is still actively fermenting it'll be a bit bubbly even if the containers it is stored in aren't very airtight. This sort of half-fermented slightly bubbly brew persisted for a very long time in Korea in the form of makgeolli. However modern makgeolli that's sold is mostly fermented dry and then backsweetened with artificial sweetener but you can still sometimes find homemade makgeolli that is only partly fermented, full of clumps of yeast, and lightly carbonated as fermentation is still ongoing as you drink it. It is delicious.
Of course expert brewers found various ways to keep bacteria at bay but many more slapdash smallscale brewers seemed to have just served it only partially fermented and very fresh. The last example of this in the UK was West Country White Ale. See here several primary source quotations: http://zythophile.co.uk/2007/11/09/west-country-white-ale-a-lost-english-beer/
All of this wasn't necessary to the same extent with wine because yeast has an easier time metabolizing the sugars in fruit juice than it does in grain which means less leftovers for the bacteria to eat. Also wine is generally stronger than beer so the higher levels of alcohol keep the bacteria out. Of course people did still end up with spoiled sour wine, but it was easier to avoid than sour beer.