In addition to the excellent suggestions by @leroydougls, you may need to perform a DFU Firmware Revive to reset the security enclave & system firmware. Unfortunately this requires access to another Mac currently running macOS 15.7+ Sequoia or macOS 26.x Tahoe. With macOS Sequoia you must use the Apple Configurator v2.19 app. The Apple documentation I linked is wrong in this regard (personal experience).
I'm not sure this will make any difference if the problem is intermittent.
You can try clearing the NVRAM by using the Terminal app. This can be done from Recovery Mode or even from within macOS itself.
from Recovery Mode (Terminal app can be found on the "Utilities" menu on the menubar):
nvram -c
from macOS (will prompt you for your macOS admin password, but nothing will appear on the screen as you type the password, so press the "Return" key to submit the password):
sudo nvram -c
You need to reboot the computer after issuing the command so that the system pulls the default NVRAM settings. Keep in mind if your macOS settings have a problem, then this won't have any effect. Clearing the NVRAM usually only helps if the NVRAM had corrupt or invalid settings.