How to connect wireless keyboard on login screen
See if this works:

Unplug ALL USB devices, have your wireless keyboard and mouse turned on, and restart. The system sees that there are no input devices and searches for them. Then asks you to type a passcode and hit return.

If you have the Apple Keyboard 2 which has the Lightning port on the back of the keyboard, all you need to do is connect the USB -> Lightning cord to the computer and it will just like a normal wired keyboard.