MacBook startup problems - mouse and keyboard not working at login / stuck on apple logo
I had the exact same issue. For me this was an issue of FileVault.
Try disabling FileVault and see if it helps. Also by cleaning the NVRAM the next boot will be OK.
Judging from forum responses this is a known issue by Apple but no software update or hardware replacement program has been announced to my knowledge.
I installed Sierra today and faced the same problem. And yes the solution also worked which is disabling the file vault.
In case you are not able to (or facing difficulty) go pass the login screen, just plug in an external mouse and a keyboard. Fortunately, they work fine and this'll help you to go pass the login screen and fix the issue.
I had a similar problem with macOS 10.12.6 on my 2017 iMac. The problem goes away when I disconnected an external USB hard drive (Sabrent enclosure) and returns when I reconnect the drive.
Have you tried booting into safe mode when this happens? That will disable any extra kexts etc and clear/rebuild some stuff so might help, if it's a software issue.
Anyways, to diagnose this properly you need to enable SSH and screen sharing and log in remotely when it happens. Check top, have a look in syslog, and see how the maschine responds to input coming over VNC...
I get the same problem, with a message to restart in recovery mode, which seems a pain. What I actually do whenever this happens is to plug the magic keyboard into the mac as if recharging - and it works straight away. Once the normal desktop is up, it can be disconnected. Seems like an apple bug to me.