Yeah, some of these long-used processes are so non-intuitive and elaborate, one has to wonder, how was it figured out. Making bread is one of the most significant and important such.
The fermentation process didn’t need to be invented, so that was probably the first step. After a couple of hundred generations of everyone around the campfire going to sleep totally hammered, someone somewhere started to do some what-if.
I found some interesting sites about the history of grain, grinding it to flour, baking it, yeast & leavening, domed ovens.
Some think that people were making flatbread (unleavened) and some foam from nearby beer making got into the flour/water mix and caused it to rise. Interesting thought.