Amongst other things because you have low control over what the dog actually learns or associates.
Scenario 1: The dog sees a bee and tries to squish it. The bee stings, it hurts, the dog associates touching a bee and getting hurt (not necessarily the first time).
Scenario 2: The dog barks at the mailman. You spank it. Why did it hurt? Because of barking? Because of the stranger showing up? Because of the car in front of the house?
For negative enforcement you'd need to always have perfect timing and it's just too easy to screw up. It's far easier to be consistent with exclusively rewarding the right behavior.
If the dog sits there patiently and it gets a treat for doing so, the exact reason - mailman appearing, not barking, car passing by - won't matter. You enforced wanted behavior. Next time there's no car, so the dog will be able to figure out it wasn't due to the car, for example.
There's nothing wrong in introducing a "no" and enforcing it by taking something or pulling the dog away. If you use a clear command, the dog can associate that with "I'm not allowed to" and possibly more important "there won't be treats".