It works the same as any sanction really - so yes if you follow a style of parenting with punishment/sanctions, then you're using that as a tool to manipulate their motivation, tipping the scales. It's based on a premise that children are misbehaving because it works for them - which might sometimes be true.
However you're right that it is an extrinsic system which has drawbacks. This is one of the criticisms of punishment as a behaviour management tool.
I see it as kind of a ladder and we can go up or down the ladder. Scary punishments are right at the bottom, hopefully nobody is using those any more. That might be hitting/pain, screaming, threat of permanent loss of something precious, being shut in a dark place etc. You might fall into this by accident if you're struggling. Maybe in the metaphor this could be a pit below the ladder!
Then you have non scary but unpleasant/unwanted punishment that is generic, such as temporary loss of a privilege or posession, grounding, time out (in a safe location) writing lines doing laps etc. That's where your question lies on the ladder for me. It's not harmful but it's probably the most crude acceptable tool in the parenting tool box. In order to be effective, you have to also combine it with positive interactions, praise, explanation, talking, problem solving etc. If you just used punishment on its own without ever doing anything else then it would not work well (unless it's scary, but then it's probably causing harm in addition to shaping behaviour).
So if you want to climb the ladder I'd suggest the following steps. Nobody parents entirely on one step of the ladder - we all move up and down it as the situation requires.
Next one is logical consequences - where you choose a punishment that has a learning or restorative or preventative outcome. So perhaps if you make a mess, then you have to clean it up yourself. If you hurt somebody then you have to play somewhere else. If you waste something then you must use your pocket money to replace it, throw food = dinner time is over, etc. Using reason and logic and explanations - giving children information about why you want them to behave a certain way, not "because if you don't you'll be grounded". Just beware of using very lengthy explanations for very small children, you must tailor it to their attention span and make the message as simple as possible.
The next step is positive parenting. Encourage and praise what you like/want to see more of, rather than discouraging the bad. A good exercise is to think of the 3 things you say no or stop to most often. For example no hitting, stop shouting, don't throw food. Frame it as a positive expectation instead.
If you feel frustrated, ask a grown up to help with brother.
Use a calm voice so I can understand you.
If you don't want it, put it on this plate.
Doing this as an exercise also helps you notice when your child is doing something right and you can praise it when you see it.
I saw that you felt angry with brother but you stopped yourself from hurting him, well done.
I'm glad that you could talk to me when you felt sad. Now I can help you.
You're all finished, thanks for letting me know, good boy.
You can also use tools like sticker charts, the pasta jar method, or a token economy system as part of rewarding and incentivising positive behaviours. This still has the same issue of being extrinsic motivation, but it's less destructive than punishment, because it helps the child build a positive self-image and focuses on what they are doing right rather than getting wrong.
Next step is skipping reward and punishment entirely but controlling the environment/using supervision to help coach in the moment. You should still immediately stop any dangerous behaviour but instead redirect to an acceptable route. e.g. child wants to throw trains, explain no we don't throw trains, let's find some balls or beanbags to throw. Look up the concept of Yes Space (RIE). Redirection is helpful so trying to see the child's point of view and understand what they are expressing with the unwanted behaviour. Is it emotional (frustration, fear, etc) can you alleviate that? Is it impulsive, can you follow the impulse and redirect that? Also, concentrating on building a positive, nonjudgemental relationship with your child in order to build trust. See unwanted behaviour as something to problem solve instead of punish. What's driving this? Can we solve the problem in a way that's acceptable to me (parent) and achievable for child? Is there something environmental that's causing it e.g. insufficient exercise, hunger, sensory overwhelm. Be curious.
Last step is probably the one that says stop focusing on behaviour at all, because behaviour (hitting, screaming, breaking things) is occurring when children are in such an emotionally elevated state that they can't control it anyway even if they wanted to, and by treating it as something that they are choosing to do, we're hurting them by punishing something that they are unable to manage. Instead see behaviour in terms of underdeveloped skills. They may be underdeveloped due to age (e.g. almost every 2 year old tantrums in response to frustration or disappointment, because their emotional regulation skills have not yet developed to a point that they can calm themselves in the face of those feelings). Work on the skills and/or wait for them to develop naturally and the problematic behaviours will go away by themselves. In the meantime you may need to avoid situations that trigger a need for expectations the child cannot yet meet. Look up Ross Greene CPS, Mona Delahooke.
Most parents never get to that top rung because they don't need it. It's often an approach only used with children who are extremely reactive to the lower rungs because they have trauma, or for whom the "standard" expectations are not appropriate because they have developmental delays. You can use it for typically developing, not traumatised children but it can be quite labour intensive and you probably don't need to because a mixture of positive reinforcement, relationship building, age appropriate explanations, controlling the environment where appropriate and yes perhaps the occasional logical or even generic punishment is a good mix for most children and they respond well to it.
Sorry this was so long. Hope it helps.