The transfer of energy in a lithium ion battery generates heat. The components in the phone generate heat.
Charging with GPS will generate the most heat as the GPS, cell radio and battery are all being used, while charging. Anything you do while charging will cause the phone to get hotter than if it were running on battery alone.
Also, the heat while on battery will come from a few sources. First, the more power it is using (GPS, CPU intensive apps, large downloads, hotspot mode, high screen brightness, etc.), the more heat will be released from the battery. Also the components themselves, like the cell radio and the cpu/gpu will generate heat. Combine all these factors in different combinations, the device can heat up.
Also, there is a known radio bug that can cause it to heat up too. If the phone loses service, it goes to max power to reacquire signal. Sometimes the phone doesn't drop to normal power after the signal is restored, causing the radio to operate at max power, generating heat and placing a large draw on the battery, again resulting in more heat. This will be evidenced by a linear decline in your battery and high heat after a loss of service. A simple reboot will solve this, though it can still happen again.
And if you are concerned about the phone overheating, it won't. If the CPU gets too hot, it will just slow down the CPU until it cools down. If the battery gets too hot, it will shut off completely. You can turn it back on when it cools down. (If it gets too hot while charging, the first thing it will do is reduce the charging current or shut it off completely, before shutting off.)