It makes it cook more evenly and also I think medieval bakes used to transport bread on wooden racks so bread with holes were more of a thing back then cuz you could easily stick them on the pegs. Pretzels and donuts also have holes in them. But I'm not a historian so maybe I'm talking out my ass
Edit: Some guy on has a more comprehensive explanation.
It makes it cook more evenly and also I think medieval bakes used to transport bread on wooden racks so bread with holes were more of a thing back then cuz you could easily stick them on the pegs. Pretzels and donuts also have holes in them. But I'm not a historian so maybe I'm talking out my ass
Edit: Some guy on has a more comprehensive explanation.