Connect an external display and close the lid. See if that makes any difference.
Otherwise you will need to use a wireless keyboard & mouse in order to modify the settings.
You can also try putting the laptop into Share Mode. You can do this using an external USB mouse because those macOS Thunderbolt port security settings are not applied outside of macOS. This option will require access to another Mac as well as a Thunderbolt cable to connect the two Macs. See the following Apple article for details:
Use macOS Recovery on a Mac with Apple silicon - Apple Support
Is the built-in Trackpad also not working along with the built-in Keyboard?
FYI, people should always have frequent & regular backups of their computer if there is any important data stored on the device. The time to worry about backups is before a problem occurs. Otherwise the user will likely lose their important data because it is nearly impossible to recover data from the internal SSD of the recent Macs due to all of the hardware, software, and security changes.