WOW!!
I was gonna hit the HAZ thread but after reading the responses there wasn't a whole lot to add.
Nobody is hittin this one so I'll take a stab, though jon's apporach in the HAZ thread is apt. This is a big question requiring more specificity to provide more specificity. But there are some generalities we can tackle. And note that my language will be metallurgically crude to the point of some innacuracy but I hope it conveys the what happens.
1) Metals wil not demonstrate the same tensile strength at high temp that they do at low temp, generally, and so welds in stress will yield at high temp, eliminating the stress. This is crude but I think generally accurate.
2) Upon heating carbon begins to move and carbides begin to precipitate (combining with metallic elements such as Cr and Mo) removing carbon from solution. Carbon is an interstitial strengthening element.
3) In some alloys this will happen with nitrogen as well precipitating carbonitrides (such as Grade 91).
4) Ductility is restored for the same reason that strength is often reduced depending upon that alloy. See above.
5) Heating and cooling rates and any damage therefrom depend upon the alloys. Each alloy has certain rates of cooling associated with certain transformation products (martensite, bainite, acicular ferrite etc.-related to alloy content, especially carbon) that are related to the hardenability of the material.
This is just the tip of the iceburg, and again very crude. There are some really good books out there that can do a far far better job of explanation than achievable in here for such a huge question.
You can Google "post weld heat treatment of carbon and low alloy steels" to obtain a wealth of information as to what metallurgical changes ocurr during the application of thermal treatment.
To answer you last question,
"4. What is the danger if we heat or cool it faster than allowed by the code? "
Heating or cooling outside of code recommended ramp rates will result in thermal gradients that translate to thermal stresses in components. These stresses, if severe enough and tensile in magnitude, can result in cracking or severe distortion. Also, depending on the alloy composition of the metal, harmful phases can be formed, like untempered martensite that could result in poor toughness.