I had the same problem, 2018 iPad Pro running 13.5.1 with the Magic Keyboard. Removing the both the iPad and the USB-C power cord from the keyboard (i.e. no power going to the Magic Keyboard from any source) seems to reset things enough to get it to start working again.
[I’m marking this just for me to find again. It doesn’t happen very frequently for me, but when it does I never remember exactly what to do… (of course, now I will)]
Source: Apple Community