Hello 4me69,
Thanks for reaching out in Apple Support Communities. Let's see if we can help find out what's going on with your iMac and the external monitor.
This is an unusual issue, so we'd like to start with trying safe mode. If you haven't already, restart in safe mode and test to see if the external monitor switches over to mirroring. If needed, see How to use safe mode on your Mac. It is normal for your Mac to boot up slower in safe mode, its performing checks and repairs much like First Aid as it restarts.
After testing in safe mode, if it doesn't occur, restart your Mac and this will take you back to normal mode. Test once more to see if behavior happens again. If so, let us know exactly which Mac and external monitor you are using and the macOS installed.
We look forward to hearing back from you.