During baking, the starch in dough melts. The molecules become less organized and allow water molecules to move near them, some are partially dissolved. As the bread cools, the starch recrystallizes or retrogrades and goes back to a solid form, which causes a firm texture. Starch retrogradation is desirable for some starchy food products in terms of textural and nutritional properties.
Why has starch retrogradation been the subject of intensive research over the last 50 years?
You can learn more about starch retrogradation here.