If your iPhone is overheating, there could be several different causes, ranging from normal heavy usage to failing internal parts.
Causes:
If your iPhone is getting abnormally hot during charging, gaming, video recording, or everyday use, there are a few common causes to look for. One of the most common causes is a degraded battery. As iPhone batteries age, they become less efficient and can generate excess heat, especially while charging or using demanding apps.
Cheap chargers can also be a cause of overheating. The reason an Apple charger costs $20 is not just because it is branded, but because it has a chip that communicates with your phone when the battery is full, so the cord automatically stops charging. A charger from Dollar Tree or Target is most likely just 2 wires that will not know when to stop charging. This can cause your phone to overheat or get damaged.
Software issues can also cause overheating. Bugged apps or outdated iOS versions may cause the processor to run constantly in the background, increasing temperatures and draining battery life faster than normal.
Solutions:
You can check your battery health by going to Settings → Battery → Battery Health. If your battery health is below 80%, it will need to be replaced.
If you believe your issue is your charging cable, you can go to Apple.com to get safe, high-quality charging cables that will keep your phone safe.
If you believe your issue is caused by software, you can check your iOS version by going to Settings → General → Software Update.