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 is replacement of the keyboard. As you appear to be within your one-year limited warranty, you need to contact Apple Support or your retailer.
You will find the Get Support link at top-right 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