Deterrence/fearofpunishment is a happy byproduct of punishment when it happens. Rehabilitation is a happy byproduct of punishment done well. Far as I can tell, punishment's primary purpose is to make everyone who plays by the rules feel good enough about playing by the rules that most of the time people just consider it easier and better to do so. They feel things are just. Just go along and get along. So long as people think punishment is fair enough for the people playing by the rules it can almost be anything. A firm scolding. A fine. A bullet to the brain for jaywalking. Lifetime unemployability for taking a leak. Whatever.