Same problem here, iMac 27” 2020, 8GB of RAM.
I’ve added the RAM information because I’m starting to think that it could be an out of memory problem, it happens when I’m using Android Studio with either iOS or Android simulators.
It happens ONLY when I have an external monitor plugged via USB-C to HDMI, never happened with external monitors connected via AirPlay or iPad with sidecar or USB-C.
It happened both with Catalina and Big Sur.
It seems completely random and it’s becoming unusable. Those PCs cost almost 3000$, it’s absolutely unacceptable