I encountered a similar problem. Matlab would freeze the system for about 20 seconds every time the mouse focus was changed. Two monitors - one connected directly (USB-C) and the other through a docking station (Display Port). I disconnected the USB-C monitor and reconnected and the problem disappeared. Apple needs to investigate this issue!! I wasted about a day of my time. I've seen similar issues previously, so this is a persistent problem Apple is missing.