To see why bread dough might collapse, you need to understand what makes it rise in the first place. Essentially, the dough is blown up like a balloon by carbon dioxide - CO2 - produced by the yeast as it ferments the sugars in the dough. For this to happen, the dough has to be stiff and strong enough to hold the CO2 in small bubbles. This is why you knead it. As the dough is repeatedly stretched, the proteins in the flour are also stretched and mixed together to form sheets of the protein complex, gluten. Gluten is like rubber: stiff, strong and highly elastic. As the CO2 is formed, it makes lots of small bubbles that slowly inflate (just like tiny balloons) and the dough rises.

However, if there is insufficient gluten, the rubbery sheets are weak and, as the bubbles grow larger, they start to burst. This leaves the dough with a few large bubbles, rather than a multitude of small ones. In such a case, if the surface of the dough is disturbed (as can easily happen when transferring the dough to the oven), those large bubbles just under the surface are punctured and the dough seems to collapse.

To avoid this, you need to knead the dough until it becomes very stiff - how long this takes depends on how much protein there is in the flour (always use a strong, high-protein flour to make bread), the temperature in the room and how much effort you put into the kneading. As a general rule, kneading for at least 15 minutes is a good idea, but the longer the better.