It’s 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. Wireless charging is less efficient than charging using a cable, so the temperature rise will be higher than charging using a cable. 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. That’s why the phone gets warm in use, also.