Second monitor turns blue problem
You can try to reset the SMC on your iMac


Shut Down your Mac
Unplug the iMac form the power cord.
Press and hold the power button for 5 seconds
Plug the power cord back in and turn on your Mac.


Also, you can try to reset the NVRAM


Shut Down your Mac
Press the power button and immediately press and hold these keys together: Option Command P and R
Keep these keys pressed down for at least 20 seconds until you can hear the startup sound again
You can release all keys after the Apple logo shows up and iMac boots normally.