Widespread consensus heavily influences prosecutorial discretion though, which determines in practice what is or isn’t permitted by society.
The law is not a computer program, and it is applied entirely arbitrarily.
Your comment makes no sense at all. For something to be a crime it has to be explicitly defined in law. Consensus has zero to do with it. Either there is a law, or there isn't. The whole point of rule of law is that you don't get to pick and choose which law applies to you in a given day of the week.
If the law is not enforced, then it does not exist. The only real law is the one that you see day-to-day. So shooting black people is fine (in the US), and you can buy weed in shops (in a few places).
Also, Prohibition.
The law is not some inviolate thing in a society. Many millions will happily ignore unjust laws if they feel they shouldn’t be laws. More alcohol was consumed during Prohibition in the US than before it was banned.
Marijuana sales, for example, seem extremely popular.
Just because there’s a law in place at some remote level of jurisdiction doesn’t mean it’s just, or has popular support.