The question is
- Have you exposed your device to a liquid?
- Have you left it outside in a car and the temperature went beyond the acceptable limits?
- What is the Health of the battery? Have you checked recently?
- What were you doing on your iPhone?
- Was it connected to counterfeit charging cable?
- Did your iPhone had a protective cover which does not provide good ventilation?
Lastly, purchase Apple Products, from an Apple Online Store, Apple Retail Stores, and many Apple-authorized resellers and wireless service providers.
Secondly, It is not clear here in your post about the ambient temperature in your area where you are using the iPhone. However --> Keeping iPhone, iPad, and iPod touch within acceptable ...
Store the device where the temperature is between -20Âș and 45Âș C (-4Âș to 113Âș F). Donât leave the device in your car, because temperatures in parked cars can exceed this range.
Use iOS devices where the ambient temperature is between 0Âș and 35Âș C (32Âș to 95Âș F). Low- or high-temperature conditions might cause the device to change its behaviour to regulate its temperature. Using an iOS device in very cold conditions outside of its operating range might temporarily shorten battery life and could cause the device to turn off. Battery life will return to normal when you bring the device back to higher ambient temperatures. Using an iOS device in very hot conditions can permanently shorten battery life.