See >>> If you see an ‘Accessory may not be supported’ alert - Apple Support
If you are using a Smart (folio) keyboard, the alert is typical of a faulty folio keyboard. The electrical connections that pass though the flexible fabric hinges typically fracture - this usually resulting in errors and/or the on-screen notification that you see.
The Smart folio keyboard itself is not repairable. The only remedy, if internally defective, is replacement of the keyboard.
A further possibility is dirty smart connector contacts. 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 remains unresolved, you would be best advised to visit the Genius Bar at your local Apple Store, where the technicians will be delighted to assist with testing the iPad and Keyboard. When visiting the Genius Bar, a reservation is recommended:
Genius Bar Reservation and Apple Support Options - Apple