have this issue on a 2015 12 inch MacBook. I used to think it was caused by a USB type C dock. I would cut the power to the dock, then the keyboard or mouse would come back.
I later bought a 2020 Mac mini. At that point I realised it is an issue with the Mac. My observations of it
-effects at least 2 different Mac hardware types
-effects keyboard plugged in to USB type A
-effects Catalina, I cannot remember if it affects earlier OSs. 10.15.1-10.15.3 all effected.
-I use wifi only for Apple Watch authentication. Not connected to any routers. I use ethernet for internet.
-no VM use.
-effects both upgraded systems, and fresh installs from the factory.
-is intermittent, and occurs rarely
-if resuming from sleep with the issue, if you sleep again, and resume later, the keyboard comes back