This is a known issue and design defect with the Smart Keyboard for the first and second gen 12.9" iPad Pro (it's the same keyboard model for both generations; incidentally, the Smart Keyboard for the 9.7" iPad Pro also suffers from this same issue and design defect). Your only solution is to take it to Apple to have it replaced under a quality repair program. Unfortunately, this is one of those flaws and quality repair programs wherein your replacement will inevitably fail in the exact same fashion. This is why I eventually sold off my first gen 12.9" iPad Pro with the intention of eventually getting a 3rd or 4th Gen (as typing is sort of a must-have for me when it comes to 12.9" iPad Pros).