If your phone is getting hot frequently, shut it down immediately and close all the apps. This will reduce the extra pressure on the phone and it will heat up less. Do not use the phone in the sun and keep it away from external heat. These can increase its heat.
The case or cover prevents the heat from escaping, which causes the phone to overheat. If the phone's battery is having problems, it may be overheating. iPhone also has a feature to check battery health. If you are using the phone on data or WiFi, turn off the network and see if the phone heats up less. The phone also heats up due to constant network search.
Sometimes the phone heats up due to not updating. In such a case, if any update has come, then install it. If the phone does not stop heating up and this problem persists, then you should do a factory reset, but first take a backup of the data.