iMac’s leverage the Intel CPU’s graphics engine at startup. Then, the MXM graphics board GPU takes over.
So as an example if you restart your system using the Startup key options you can stay with the Intel graphics will still be active.
Sadly, it’s likely the system an MXM board needs some cleaning and replacing of it’s TIM both paste and pads.
I would install a good thermal management App like [https://www.tunabellysoftware.com/tgpro/|TG-Pro] which I find is the best! As you need to see clearly what’s happening and boost the fans to help keep things cool.