So, here’s some of why premodern farming and advancement assumptions don’t work in this discussion, if we go by the core books assumption that every other thorp and hamlet has someone who can cast 1st level spells or cantrips or something, and even up to 3rd level spells aren’t that uncommon.
Food and drink are easy to store, and keep fresh, and recover when it does go bad.
Irrigation is easier.
Creating fire is easy and requires less fuel.
People are cleaner and clerics and Druids and such have a better understanding of disease.
Druids have an easy and obvious incentive to help farmers grow more efficiently and sustainably.
Common magic items.
Fast communication is easier.
On top of that, if a medieval society did develop such mass agriculture capabilities, they would almost certainly be used to feed people before making fuel. If those advances happened very quickly, as in the real world over the last 200 years, there might be enough excess to use it as an energy source... but if they happened gradually, population growth would literally eat up all the benefits.
Malthus gets a bad rap nowadays, but his fundamental reasoning held true for almost all of recorded history. What he didn't foresee was the explosive growth of technology in the last two centuries which let our capacity to feed people outstrip people's capacity to have babies. If the same technologies had been developed over 1000 years instead of 200, we'd still be in the Malthusian trap today.
(And as a side note, that real-world agriculture technology is overwhelmingly dependent on fossil fuels, too--not just as an energy source for the machines, but as fertilizer. Modern farming is in large part a system for converting petroleum into people.)
Just a bit of an aside. Food surplus isn't a modern invention. Malthus gets a deserved bad rap, because his reasoning never really held up in any sort of general way, and his understanding of people was cynical to the point of being anti-social.
The idea that any increased production of food would just be eaten up by population growth only works with some very specific, dubious, assumptions. First, that the increase in production wouldn't come alongside an increase in quality of life and of life expectancy, which tends to slow population growth. Second, that there is no limit to how much people will just make more babies. Third, that there would not also be an increase in the technology of
keeping food.
Change those assumptions, and the entire picture changes. Using the magical assumptions of the 5e core books, the above assumptions don't really work.
The other thing people tend to ignore in this discussion is that we aren't talking about a world that developed like Earth did up until some classical history date, and then magic started changing things. We are talking about a world where we evolved alongside magical creatures, and our first tools may have included rudimentary magics.