Right now, in my one group the PCs are part of the city watch, so enforcing the laws is on them! But in general, I try to be guided by a balance of consequences and fun. If the PCs get caught stealing or outright just murder a high-ranking NPC, they're going to have to deal with the consequences. It might be hard labor, fleeing, or being conscripted into undertaking a specific task - whatever it is, it has to lead to more adventure. I'm not likely to enforce a death penalty, as that doesn't generally lead to more adventure. If the laws indicate you lose a hand for thievery, well you can bet there's going to be an adventure to get a cool prosthetic.
Now, if it's a problem player going out of their way to get into trouble, or a PC that persists in disruptive behavior, the law will come down hard on them and only them. That won't lead to more adventure, only a quick cut scene of "you've been arrested, you have to pay this fine (GP or a magic item), and okay, now we're back in the main narrative." They will also get an out-of-game warning.