How to debug iPhone overheating when the cause is clearly not the environment when the phone is used?
I would advise phoning Apple first. you will be able to speak with someone regarding the overheating error you are having. 

They will more than likely tell you why, and failing that recommend that you go to an Apple store. They will look at the device and run diagnostics.

If you report an issue with a product at the store and the issue cannot be replicated they will usually replace the device with a refurb model on the spot. I have had this happen twice (the swap, not the overheating) once with an iPad and the other an iPhone 3GS, both were replaced.

Yes the sad thing is that they will need to wipe all the data if they cannot fix it after diagnostics. You will hopefully have a backup on your computer, or if you used iCloud a back-up in the cloud, which you can start to download instantly at the store.

Hope it works out for you