The answer is that dogs sometimes pant just to keep cooled off.
When your body temperature gets too high, you sweat. Evaporation of water takes up a lot of heat. Evaporation of sweat from your skin helps cool your body when its temperature begins to get too high.
Dogs (and cats, too) are pretty well covered with hair and have very little bare skin. They can't keep cool by sweatingexcept maybe a little from the pads of their feet. Instead, a dog pants. That moves air rapidly back and forth over the moist tissues of its mouth and tongue.
Panting is the dog's way of evaporating extra water to help keep its body cool.