If you’re experiencing a sporadic problem with your Mac, the sort of thing that happens often enough to be annoying but not so frequently as to be reproducible, allow us to suggest one little-known troubleshooting tip.
Malfunctioning USB devices—keyboards, mice, hubs, printers, etc.—can sometimes cause truly inscrutable problems ranging from startup issues to kernel panics. USB-caused issues aren’t common, but when they do happen, they can be challenging to track down.
If you’ve tried everything else, disconnect all unnecessary USB devices and, if possible, swap your wired keyboard and mouse for another set. Then see if the problem goes away.