I am relatively sure it is some kind of driver or firmware issue. My Surface Pro 4 worked perfectly up to one of the updates, then the keyboard never worked again.
Microsoft tried many things even up to a complete reload of Windows, nothing worked. In the end, I purchased a new Surface Pro 7.
An interesting note is that the keyboard cover from the Surface Pro 4 is now attached to the Surface Pro 7 and working perfectly.