There are two possible punishments: beating or confinement.
If only one option is available all punishments will be converted to that one.
While beating has an advantage training your doctors and potentially even finally use that hardwrought tractionbench, you also stand a risk to loose dwarfs you happened to like.
You can avoid most beatings by having a prison. A prison is designated from either a build chain or cage. Cages are safer in use when dealing with dwarfs on the edge of a mental breakdown. To avoid it comes to that, use chains and put drinks and food in range. As a chain gives some leeway, you can take care of other needs too.
Still, not complying to noble demands is a very serious offence! Something that very well can end up with a capital punishment. As others answered, there will be no beatings when there is no executioner.
When a crime is not punished, some dwarfs will feel unhappy about it. Punishing a random innocent will make eveb nire dwarfs unhappy. Unpunished crimes will be remembered a long time, potentially making your hammerer very busy once you assign one.
An assigned hammerer can be fun if you manage to intercept an artifact thief, Once you are used to how dwarven injustice works, you can evade the worst consequences. Most of the time. Do not get too attached to your dwarfs. There will be !fun!