In pure water, the vapour bubbles that form near the bottom of the pot rise up to the top and burst, but milk (and other liquids, such as pasta water once it has starch in it from the pasta, and water with detergent added) has lower surface tension, so when the bubbles rise to the top they can form a foam.
If the liquid is heated relatively slowly then there is time for the foam to disperse at the liquid/air interface as fast as it forms. The foam can disperse either by the bubbles popping as they are exposed to the 'air' above the surface, or by the vapour in the bubble cooling and the bubble collapsing (if the surface of the liquid and surrounding air is below the liquid's boiling point).
But if it is heated too quickly then the foam doesn't disperse as fast as it collects. New bubbles are trapped below a surface layer of existing foam - because they are not exposed to the air they don't pop, and because the foam is a good insulator they don't cool so quickly and therefore don't collapse. Even if foam production is initially only slightly faster than foam dispersion there can be a runaway reaction as the gathering foam has a negative feed-back on foam dispersion.
At he same time, the foam layer now reduces evaporation from the surface of the milk, so it heats faster for the same thermal input from your stove element. The upper surface in particular will heat up rapidly as that was the region that was kept coldest by evaporation before the foam layer started to form. So the foam layer (as well as acting as negative feedback on foam dispersal) also acts as positive feedback on liquid temperature and therefore on foam production rate.
When cooking pasta - a common 'trick' to stop the pasta water from boiling over in the same way, is to add a teaspoon of oil to the water - that stops foam from forming so the feedback effect never starts.