You mentioned "decoupling" the iPad from the Keyboard - but made no mention at all of cleaning the Smart Connector contacts.
If you have cleaned the contacts as suggested and the problem persists, then a hardware fault may have developed. The electrical connections that pass through the flexible hinges can fracture leading to intermittent internal connection. The Magic Keyboard for iPad is not repairable; if faulty, the only remedy is replacement of the keyboard. If you are within your one-year limited warranty, you would need to contact Apple Support or your retailer.
You will find the Get Support link at top-right and bottom left of this page.
Alternatively, you can initiate a support case using the excellent Apple Support App. If not already installed on your device, the App can be downloaded from the App Store:
https://apps.apple.com/gb/app/apple-support/id1130498044
A further alternative is to visit the Genius Bar at your local Apple Store, where the technicians will be delighted to assist. When visiting the Genius Bar, a reservation is recommended:
Genius Bar Reservation and Apple Support Options - Apple