This happened to me, too. M4 Mac mini, wired Apple Extended Keyboard, connected via a USB-C to USB-A adapter. See the thread < New M4 Mac mini susceptible to low temperature? >.
In my case, the problem occurred very infrequently. My solution: use the mouse to switch to the ‘guest’ account, which doesn’t need a keyboard to log in. Then open Notes app and type some characters from the keyboard. If it works, then log out and switch to the regular user account.
I have heard that the cause might be the signal that recognize the keyboard at startup is so low-powered, and is sometimes missed. Wait for the Mac to warm up, and then restarting might work.