Maybe check your power supply? I've supported Macs for a couple of decades and normally people have storage mounted for years without this kind of thing happening in the absence of some sort of hardware or environmental problem.
I wouldn't know what to check my power supply for and how I would go forward with that in an iMac. And this phenomenum isn't limited to the iMac, my Mac Mini had the same problem. Across different disks and interfaces. The disconnects are not constant, but an irregular thing. A colleague occasionally has the same problem, he even managed to get a local disk image unmounted when waking from sleep. So it might just be a MacOS problem.
With Thunderbolt3, there are more solutions for external storage, but still I find it odd consindering the price, that you don't get a desktop Mac where you can plug in some NVM SSDs or you get at least a few 2.5 inch bays.