The starch forms a loosely bonded network that traps water vapor and air into a foamy mass, which expands rapidly as it heats up.
Starch is made of glucose polymers (amylopectin is one of them, shown here):
Some of the chains are branched, some are linear, but they all have $\ce{-OH}$ groups which can form hydrogen bonds with each other.
Let's follow some starch molecules through the process and see what happens. In the beginning, the starch is dehydrated and tightly compacted - the chains are lined up in nice orderly structures with no water or air between them, maximizing the hydrogen bonds between starch polymers:
As the water heats up (or as you let the pasta soak), water molecules begin to "invade" the tightly packed polymer chains, forming their own hydrogen bonds with the starch:
Soon, the polymer chains are completely surrounded by water, and are free to move in solution (they have dissolved):
However, the water/starch solution is not completely uniform. In the middle of the pot of water, the concentration of starch is low compared to water. There are lots and lots of water molecules available to surround the starch chains and to keep them apart. Near the surface, when the water is boiling, the water molecules escape as vapor. This means that near the surface, the local concentration of starch increases. It increases so much as the water continues to boil, that the starch can collapse back in on itself and hydrogen bond to other starch molecules again. However, this time the orderly structure is broken and there is too much thermal motion to line up. Instead, they form a loosely packed network of molecules connected by hydrogen bonds and surrounding little pockets of water and air (bubbles):
This network is very weak, but it is strong enough to temporarily trap the air as it expands due to heating - thus, the bubbles puff up and a rapidly growing foam forms. Since they are very weak, it doesn't take much to disrupt them. Some oil in the water will inhibit the bubbles from breaking the surface as easily, and a wooden spoon across the top will break the network mechanically as soon as it touches it.
Many biomolecules will form these types of networks under different conditions. For example, gelatingelatin is a protein (amino acid polymer) that will form elastic hydrogen-bonded networks in hot water. As the gelatin-water mixture cools, the gel solidifies, trapping the water inside to form what is called a sol-gel, or more specifically, a hydrogel.
Gluten in wheat is another example, although in this case the bonds are disulfide bonds. Gluten networks are stronger than hydrogen-bonded polysaccharide networks, and are responsible for the elasticity of bread (and of pasta).
DISCLAIMER:
- pictures are not remotely to scale, starch is usually several hundred glucose monomers long, and the relative size of the molecules and atoms isn't shown.
- there aren't nearly enough water molecules - in reality there would be too many to be able to see the polymer (1,000's).
- the starch molecules aren't "twisty" enough or showing things like branching - the real network structure and conformations in solution would be much more complicated.
But, hopefully you get the idea!