"It happens so often that I always have my non bluetooth mouse and keyboard connected to the iMac"
^^^^^
This is "the answer".
Do you have any USB3 devices connected to the iMac?
USB3 seems to produce RF interference that can "get in the way" of BT.
Also, could have something to do with wifi.
BT is a "weak signal" by design.
If you can put up with non-BT keyboard and mouse, again, go with "what works".
I've always preferred a WIRED keyboard, which I use with a wireless mouse (Logitech which uses its own RF receiver, not BT).