It is normal for any electronic device to get warm when being charged or discharged. The iPhone has built in over-temperature protection, and will shut down if it’s temperature exceeds safe limits. If this doesn’t happen the phone is not overheating.
This heating effect is called the Second Law of Thermodynamics. Anything that creates or uses energy does so with some loss. That lost energy is expressed as heat. So when you charge the phone it generates heat in the power source, heat in the charger circuit in the phone, and heat as the energy goes into the battery. The faster the charging, the more heat is generated. Likewise when you discharge the battery; not all of the energy from the battery gets to the circuits that use it. Some of it becomes heat. If you use the cellular network for voice or data, converting energy to radio frequency signals is very wasteful; only about 30% of the energy that goes into the network components comes out as radio signals, which means that 70% of the energy from the battery is wasted heat.