What should we do with those who commit heinous crimes? What about those who commit minor crimes?
Punishment as a deterrent--like any overt deterrent, I suppose--functions as a threat. If you misbehave, you will be hurt or slain, or something will be taken from you. Yet that isn't where punishment ends, psychologically: people feel a rage towards particularly vile criminals, a rage that is more of a bloodlust or "righteous" fury than anything else. In these moments, the thinking is not, "We must make a warning to keep others from doing this", but rather, "That bastard must pay!"
Someone who hurts others deserves to be hurt themselves. When paired with the view that those who do good deserve good themselves, this sentence is a very near relative to the Golden Rule. We see the sentiment naturally manifested in the Judeo-Christian punishment of sinners and reward of believers, and indeed, in Jesus's famous explicit formulation of the Golden Rule. Hinduism's principle of karma is another example; even if it's not seen as a "punishment" per se by the Hindus, clearly it stems from the same sort of thinking. More recently, the neo-Pagan/Wiccan Rule of Three tells us that our decisions, beneficent or maleficent, will be visited upon us again, with threefold consequences.
Nietzsche described the general punishment urge in depressingly incisive terms:
... to what extent can suffering be a compensation for “debts”? To the extent that making someone suffer provides the highest degree of pleasure, to the extent that the person hurt by the debt, in exchange for the injury as well as for the distress caused by the injury, got an extraordinary offsetting pleasure: creating suffering—a real celebration, something that, as I’ve said, was valued all the more, the greater it contradicted the rank and social position of the creditor. I would quibble with him here about harming others being "the highest degree of pleasure" for most people, but I think the general gist of this passage is right. Causing others to suffer, in certain contexts, brings pleasure which is supposed to "make up" for wrongs perpetrated against oneself. (If "pleasure" is too strong a word, then "satisfaction" may be substituted, though mayhap that sugarcoats the situation too much.)
Considered less aesthetically and more economically, as it were, one gets the impression that there exists some metaphysical balance or scale, upon which doing wrong tilts the scale; and this tilting must be accounted for. "Harm" or "hurt" is the currency being weighed here, and so a person (or, more usually, a government) does what would normally be "wrong" to a criminal, and thus the upset scale is righted.
When generalized and made normative, we call this meting out of harm for harm "justice". For Western culture, Lady Justice (Justitia) symbolizes the concept quite plainly: she carries a scale of judgment and a sword, the first for determining where and how much harm to dole out, and the second for applying it. In "civilized" societies, now that we feel a conflict between wanting wrongdoers to suffer and squeemishness about the dirty work that that entails, we do not directly apply punishments ourselves; instead, we license a certain body of people--viz., the government and its police force--to enact the tenets of justice, which is to say, the tenets of reciprocity. Not literal reciprocity in the sense of an eye for an eye, of course; we are sufficiently advanced that we can invent substitutes and equivalents such as fines and imprisonment. Or, in some dire cases, the punishment probably exceeds the crime quite excessively.
Actually, the vast majority of crimes don't incite much ire (bloodlust) in the average citizen, because the vast majority of crimes are misdemeanors that do not directly harm individuals. Jay walking; smoking cigarettes in a non-smoking area; smoking marijuana; downloading and sharing copyrighted material illegally on the internet; most other forms of copyright infringement; violating the terms of agreement in a competition or an online game by cheating; minor speeding or another small traffic offence; violating a zoning ordinance, that sort of thing. While opponents of drug use agree abstractly that smoking marijuana deserves punishment, I do not think they actively feel rage when they see or hear of such use, as long as it is not, say, "contributing to their children's delinquency". Players of an online game may feel that cheaters should be banned from the game--and in a fit of passion, perhaps more than that--but they typically do not believe that cheaters should be fined or locked up. (Indeed, perhaps these aren't even "misdemeanors" or "infractions", although most of the time legal agreements have clearly been broken.)
Along the continuum of wrongdoing, two things influence a bloodthirsty emotional reaction: personal impact, which is to say, how much an individual is personally affected by it, and severity or depravity of the crime. The former is more of a selfish thing, perhaps, insofar as we tend to care less about vandalism when it is not our very own property or part of a public space we care about. The latter is more universal or normative insofar as we can be riled up by hearing about child molesters, serial killers, or any perpetrator who inspires serious revulsion in us in spite of our own lack of personal investment in the matter.
 The Genealogy of Morals, more specifically the online edition here, because I'm lazy. Second essay, §6.
 "Misdemeanor" may not be the appropriate legal term here. "Infraction" or "regulatory offence" might be better. I should also add that whether another person is directly harmed or not can be argued in each of the following examples, but hopefully you can put that aside or mentally substitute your preferred examples as necessary.