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).
blacksmith37's answer is quite correct. An article from 2015 (Ref 1) shows the colors developed on stainless steel over a period of 10 minutes at 650ºC in laboratory air.
Ref 1. https://www.tandfonline.com/doi/abs/10.1179/0960340914Z.00000000083 This page lists several options, one of which is to download several articles; the one from which the color chart was obtained is the first, by Higginson.