You as an adult do not use physical violence against a two-year-old, ever, because a two-year-old is incapable of posing a physical threat to an adult -- we're capable of picking up two-year-olds and physically moving them somewhere else (or at least of asking another adult to do that for us), and you don't use physical violence against someone you can do that to. Just to be super clear about what I'm advocating and not advocating, it is never okay to hit a child.
You as an adult do not use physical violence against a 16-year-old, either, because of the unequal power dynamic that exists between adults and people legally classified as minors. Except... it gets tricky, since you probably can't physically pick up a 16-year-old and move them somewhere else, and a 16-year-old is old enough to pose a physical threat to an adult. I refuse to draw a line that says "here's the age where it becomes okay to respond with violence", but I think most of us would agree it's OK to use self-defense against a 16-year-old who is actively trying to harm you, in the same way that it's OK to do the same against a 23-year-old who is actively trying to harm you. I'm talking about self-defense here, not discipline.
If we're parents, at least if we're good enough parents, we teach our children how to emotionally self-regulate because we're aware they aren't born knowing how to do that and it's a skill they need to be taught. The reason you stop a two-year-old from running into traffic is that they need to survive to get to be old enough to learn how to cross a street. You stop a four-year-old from pulling their brother's hair because they're not yet old enough to learn that they're capable of hurting other people and why they shouldn't. If you expect more than a two-year-old is developmentally capable of, that's going to be bad news for you, the child, or both. (People who know more about child development than me can argue about the specific ages, but hopefully you see the point.) Since a very young child can't understand or set boundaries either for themselves or others, we do it for them until they can do it themselves.
Then the question is: in society, what do we do when we meet adults who never learned those two-year-old or four-year-old lessons, or who did learn them and choose not to apply them because they think they will get something (usually money or power) by ignoring boundaries?
This is what we do:
Very young children can't reason on the level of "if I do X, Y will happen", which is why we have to act directly to protect children we're responsible for, rather than letting them learn for themselves what happens when you run into traffic.
Young children can reason on the level of "if I do X, Y will happen", but can't yet internalize the principle of "I shouldn't do X because I don't want to be a person who does X", which is why practices like time-in work: if they know that acting a certain way results in a parent temporarily withholding attention, they will learn not to do it.
Older children can understand the difference between right and wrong, which is why we can explain to them why hurting other people is wrong and they shouldn't do it, rather than just showing them there will be consequences if they do something wrong.
Adults can understand all of this and choose to suspend their own ability to differentiate between right and wrong in order to operate on a more child-like level of "I do this because I can." Unlike very young children, they're capable of organizing genocides to show just how powerful they are and what they can do.
It is imperative not to use violence against children, for a multitude of reasons. We have no such imperative to protect adults who pose a threat to us. You must never hurt a child because you're angry. Likewise, you must never hurt an adult only because you're angry. It's very reasonable to be angry at someone who threatens your life, and in those cases, you react to the threat to your life and anger is just a side effect. We can solve problems posed by young children without hurting them. Sometimes, adults pose problems to us that rule out the option of not hurting them. We are not their parents, and do not have the power over them that a parent has over a child. We are not obligated to act as their parents, though when there is mutual consent, we can do some of the work parents do for them in a situation-specific way (we usually call the people who do that work "therapists").
In situations where we cannot enforce laws or other boundaries, we must set norms instead. It's usually preferable to set norms with words rather than fists. But words aren't magical, and the limitations of language do not require us to sacrifice ourselves and our friends on the altar of nonviolence. Every piece of available evidence shows that words are insufficient to protect each other from organized groups of adult humans attempting to recruit more humans for Nazism, ethnic cleansing, or genocide (pick your preferred term).
That was the theory; here's the practice:
Thanks to staranise for this post, and siderea for comments on that post, which sparked this idea.