This is the true, correct purpose of law — however, we currently are in a society where 'law' (and the appearance thereof) have little to no correlation to punishing evil doers. The War on Drugs is a good example here: there are things (policies, procedures, etc) which are not lawful, but which are excused in order to punish things under what is purported to be law (e.g. warrantless searches, 'expedient circumstances', [civil] forfeiture, etc.)
The heart of these laws can be seen by their fruits: in the case of the War on Drugs it is the erosion of virtually all of the Bill of Rights. In many other laws it is the government asserting its superiority over the citizenry, usually to the effect of turning them into subjects and imposing tyranny.
I am no fan of the war on drugs. I don’t think it has been fought very well. First, declare war. Next, don’t let piddling things get in the way. The purpose of war is not to kill privates, it is to subdue systems of government.
Applied to the drug trade, it is not helpful to jail those who have smoke dope. It is helpful to shock and awe the masterminds. We’ve fought privates and recruits and thought that was the war.