Year 11 chemistry student here. I'm curious about how the case hardening effect works on metals. I know that when the electrons gain an energy 'level' or lose an energy 'level' they emit light at differing frequencies. So why does the outside of metal, after being heated, stay those pretty rainbow colors after they cool down?
Case hardening (carburizing or induction or flame) does not color steel. You are seeing “temper” colors which are unrelated to case hardening. It is caused by different thickness of very thin layers of iron oxide. These colors were developed during tempering heat-treatment after case hardening. Starting with yellow, then blue and purple in a continuous transition. Faint yellow starts about 300 °F, longer times give more color development of color.
The same colors also develop on stainless steels and titanium at different temperatures and times. A stainless motorcycle exhaust pipe will show the range of colors as temperature changes along its length. If a titanium weld shows yellow color it has been exposed to air at elevated temperature (and is likely defective because of absorbed oxygen and nitrogen).