The punishability of "legal offences" accrues from morale and ethics and from nothing else, this is the suggestion I've floated, and even offences seemingly detached from morale ultimately refer to the violation of a valuable moral interest.
If this wasn't true you couldn't even explain the differences between codes from different cultural spheres, whereas their commonalities - invariably - are either the product of recent external influences or date back to the oldest days of our kind (common taboos such as that on incest for example). Furthermore you could not explain the fact that societies (or at least parts thereof) often object legislation that's not arisen from their own moral concepts, sometimes to the point where they decide to defy the threat of punishment and impose their own law.
This is why I've stated the only purpose of a penal code is to protect a morale concept and where you speak of "the purpose to determine what's permitted and what's not" I just see the underlying influence: "What's permitted and what's not" is, when all is said and done, a product of moral considerations no matter how abstract this thought may seem to begin with.
This concept suffers restrictions from the politicisation of the law enforcement and - execution, and sometimes internal resistance in terms of feasibility but I do hold it as ultimately true and I am highly critical of attempts to erode it, such as what I think the decriminalization of drugs is.
That's all I have to say for now.
Your example with regard to alcohol and tobacco is misleading and misplaced. Their consumption is not morally accepted without exception but a ban is hardly feasible due to widespread presence and cultural roots. My theory still stands, though, since where moral objection begins to prevail societies also begin to exert an influence on a level of escalation lower than punishment (but still with the character of a punishment) - in form of cigarette tax for example. Where I live it's not just a tool for the state to make money but it's declared intention is to make smokers quit, in lieu of an outright ban that couldn't be enacted.
This "self-induction" can be regarded as a punishable offence. For example, some societies do also punish crimes committed in a drunken stupor and if they don't, they'll punish the perp instead for deliberately allowing themselves to get in a situation where they could not fully control themselves, committing a crime in the process.