To put it in simple terms, when the air in your tank expands, the molecules have to speed up to occupy a larger volume (even though the air is now under less pressure). The air has to take on energy in the form of heat for this to occur and it draws the heat from the valve and first stage through which it passes as it expands.
So the metal parts of the first stage get cold and unless they can in turn transfer enough heat from the surrounding water, their temperature will fall below freezing and the water surroudning them will begin to freeze on those parts.
If the ice accumulates in an area, like the inside of the ambient chamber, where the ice blocks the movement of the piston or diaphragm, then the regulator will get stuck in an open position and a freeze-flow will result. This occurs as the pressure increases inside the first stage even after you stop drawing air through the second stage and this excess pressure vents itslef through the second stage whihc is designed with a downstream bias in the poppet assembly to allow this to happen. It's a good thing as it prevents the low pressure hoses from exploding.
This large amount of exanding air then really cools the first stage and the ice forming on it acts as an insulator further reducing transfer and pretty much ensures the reg will freeflow until the tank valve is turned off.
In the past, when all metal second stages were common, a second stage freezing up was all virtually unheard of. However when plastic second stage cases were intorduced, and even more so when plastic air barrels became common, the heat transfer ability of the second stage was greatly reduced and the slight cooling of the air dropping approximately 140 psi from the intermediate pressure to ambient pressure proved to be enough to cause ice to form inside many second stages.
What normally happens is that the ice forms on the lever or the poppet assembly and prevents the valve from closing once you are done exhaling. The frozen second stage will then often cause the first stage to freeze up as well.
A sealed ambient chamber helps to prevent a freeze up as does a metal second stage or a second stage with a metal air barrel. Pulling back hose covers to fully expose metal fittings on the first and second stages aides heat transfer and makes the reg more resitant to freezing up. The diver can also help reduce the cooling that occurs by not testing the reg or filling the BC with the power inflator and generally trying when ever possible not to flow any air through the reg until the first and second stages are fully sumberged as water is about 80 times more efficient at heat transfer than air. Check the reg for proper function at home well before the dive (giving it ample time to re-warm prior to the dive and inflate the BC at home and/or wait until you are in the water to inflate it or a dry suit.
During the dive, take care not to inhale and inflate something at the same time or in rapid succession. Also, don't drop to the bottom severely negative and then fill the BC or drysuit with a long blast on the inflator. Several smaller hits on the inflator over a longer period of time gives the reg more time to recover the heat it loses.
Low pressure tanks also help reduce the cooling load on the first stage compared to high pressure tanks. That said, many freeflows occur in the middle or toward the end of the dive due to a slow buildup of ice on or in the regulator so don't get sloppy just because the tank pressure is low later in the dive.
Generally speaking regulator freeze ups do not occur in water warmer than 50 degrees F, and they are much more common at temps below 40 degrees F where the temperature of the water is closer to freezing and there is less potential heat transfer that can occur between the regulator and the water it is in contact with.