Hello Majd! Thank you so much for reaching out, I am Harvie an Independent Advisor, and I am glad to assist you today with this issue.
It is great to hear that your Surface Pro 9 has been solid up until now. Here's some steps to fix your keyboard issue.
Clean your connector first by gently wiping the magnetic keyboard port and pins on both the Surface and the keyboard with a soft dry cloth. Detach the keyboard then reattach it slowly until you hear a click.
You may also try to hold power plus volume up for 15 seconds to force restart your device then release and wait 10 seconds and power it on normally. Also check in UEFI, turn off your device and press volume up plus power to enter UEFI then if the keyboard works there it is a software issue if not likely hardware.
Try to update your drivers on settings under Windows update and check for updates. Install anything listed under Firmware or Surface updates. Lastly try to test Another Keyboard if another Surface keyboard works yours may need repair.
If it still doesn't respond even in UEFI it is best to replace your keyboard instead.
Best regards,
Harry