1.- To break a child out of an emotional meltdown. (I used to have panic attacks and physical pain was what helped me break out. I'd usually just use cold water on myself, but a child may not be aware of how to do that and probably wouldn't choose to.)
2.- When the negative behaviour can't be talked about. If you have a two-year old in the habit of climbing book-cases, how do you explain bone-fractures, severe pain, crushed skulls and death to them? What is more likely to traumatize a kid that age: connecting "book-shelf-climbing" and "smack to the bum" or having someone show them what they'd look like if a shelf ever fell on them? Because, to a kid that age, death is something sad that just happens to others, not something that happens to THEM and explaining "a falling book-shelf can hurt you" may not suffice. The idea of punishment acts as the main deterrent until the child understands the danger.
As for fear: why don't you climb on the handrails of bridges? Why don't you stick your hand in fire? Fear is the main reason most of us are alive. But young kids, who often struggle to understand concepts such as death and the frailty of the human form, are fearless, at least inasmuch as they don't fear abstract concepts, or things they have not experienced. Until they have felt the consequences (burnt hand) they won't stop endangering themselves for fun (sticking hand out to "catch" a flame). They're even more reckless when it comes to the lives and safety of other lifeforms, like babies. A fear of physical pain could be the only thing between some kids and an encounter with death.
Physical punishment may only be required twice in a child's entire life, but, when it's required, a parent shouldn't just "be nice" and let the kid continue to endanger themselves.