The tags appended to your post suggest that you have a fifth generation iPad Pro. Presumably you refer to the dedicated folding Magic Keyboard for iPad that connects to your iPad via its Smart Connector. This keyboard has a USB-C charging port within the spine of the folding keyboard.
This Magic Keyboard has no battery of its own. It is powered from the connected iPad, or the iPad's Power Adapter when connected to the spine connection.
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 would be best advised to 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