In the beginning, the iMac reboots twice, it could be a kernel panic issue. And then the iMac crashed, and you can't boot it up, the culprit could be the startup disk, the OS, the peripherals, etc.
The "Your computer restarted because of a problem" message indicates that there may be a hardware problem, software problem, or both with your Mac. It's a kernel panic, technically speaking. As you said, you can use the Target Disk Mode to access and even boot from the iMac hard drive, the startup disk should be fine.
As you said you can't get into Safe Mode, macOS Recovery Mode, and Verbose Mode, and can't boot from a USB, and all of these require to use the keyboard shortcuts, so it is necessary to check whether the keyboard is defective. After you fix the MacBook keyboard not working issue, you can continue to try Safe Mode, macOS Recovery Mode, and Verbose Mode to reinstall macOS, allow to boot from a USB installer, etc.
In addition, the connected peripherals may be malfunctioned and prevent the Mac from booting up normally, you can disconnect all the accessories and perform a restart again.
As long as you can successfully enter macOS Recovery Mode, you can recover data from unbootable Mac with iBoysoft Data Recovery for Mac, if there is no Time Machine backup, you can save your Mac data in this way.