Remove the iPad from the Keyboard - and carefully/gently clean the smart connector contacts on both the iPad and keyboard with a soft pencil eraser (a drafting-film eraser is ideal). Ensure that the contacts on both iPad and keyboard are dirt and dust free - and all debris from the eraser have been removed - before reconnecting the two.
If you can't connect your iPad to your Magic Keyboard, Smart Keyboard, or Smart Keyboard Folio - Apple Support
If the problem persists, you might be well advised to seek assistance directly from from Apple Support. You can contact the Support Team using the Support link at top-right or bottom-left of this page. Alternatively, you can initiate and manage your support cases from Apple devices using the excellent Apple Support App. If not already installed, the App can be downloaded from the App Store:
https://apps.apple.com/app/apple-support/id1130498044
You might also visit the Genius Bar at your local Apple Store or Apple Authorised Service Provider (AASP) - where the technicians will be able to test and assess your iPad and keyboard:
Genius Bar Reservation and Apple Support Options - Apple