I hope this helps someone as it worked for me. When this occurs, the only trackpad works, the touch screen works, but only the power button and Fn buttons work on the keyboard. When I go into Device Manager, the Surface Hid Mini Driver has a yellow triangle over the icon.
To fix the issue, I simply right-click, click "Disable", then accept whatever warning it gives me about the device stopping (DO THIS AT YOUR OWN RISK, it didn't cause any issues for me). Then, right-click again, click "Enable". And BOOM, the keyboard works again without even restarting the machine.
This has happened twice in the last 6 months and makes no sense. I'm mostly posting this so that I'll have the note for myself in the future when it happens again. I hope this is able to help someone else. Extremely infuriating that Microsoft hasn't been able to give the rest of you a reasonable solution.