Did you already force restart your iPhone?
...
- Press and quickly release the volume up button.
- Press and quickly release the volume down button.
- Press and hold the side button.
- When the Apple logo appears, release the side button.
...

...
copied from: Force restart iPhone - Apple Support
In case this does not solve the issue, set your iPhone back to factory settings without using the backup and test it again:
How to factory reset your iPhone, iPad, or iPod touch - Apple Support
If you are still getting the temperature warning without the iPhone getting too hot, you should contact the official Apple Support and ask them to diagnose your device online:
Contact Apple Support - Apple Support