Why do they stand on one leg?

This is not a punishment. It is a very common posture for most birds. Nature has endowed them with a mechanism, that allows them to place only one leg directly under the center of gravity of their body. This way they spend less energy than if they stood on two legs.

Scientific research has shown that birds hardly move their muscles when standing on one leg. This also makes it easier for them to maintain balance. They can even sleep on one leg, thus combining rest with energy conservation.