Phones have no fans, so every watt of energy used ends up as heat leaving through the case. Sustained work such as navigation, gaming or video calls produces heat faster than a thin aluminium or glass body can shed it.
Charging adds its own heat, and fast charging adds more. Charging while using the phone stacks both sources, which is why a phone on a car mount running maps in the sun becomes uncomfortably warm within minutes.
When a phone gets too hot it deliberately slows down. Screen brightness drops, performance is reduced, and charging may pause entirely. This protects the battery, which ages considerably faster when kept hot.
A phone that runs hot while idle is different. That points at an app stuck in a loop or a poor mobile signal keeping the radio at full power, and it is worth investigating rather than tolerating.