I saw a good cleric PC lethally attack and kill 2 city guards just because they thought he "murdered" the dead guy the PC just killed (the guy tried to rob the PC and he killed him). The guards told the PC if he pays them to overlook the situation, they won't arrest him. Instead, the PC drew his weapon, and the guards tried to grapple him (for an arrest), they failed, and the cleric used his magic to kill them both in 1 round.
Ignoring that this event came from a preoblem player, here's how a player probably looked at those events:
Guy tries to rob PC, PC kills guy as act of self defense. Fully justified under Texas' Castle Law which allows for use of lethal force in defense of life or property for yourself or another.
Then 2 cops try to take a bribe from him at the scene and try to arrest him. This was illegal, so the PC went all Castle Law on them, too. The cops should have brought him in for questioning, "we just need to bring you to the station, make sure you're all right, and ask you a few questions, standard procedure in a situation like this, you know..."
Under general terms, one is only allowed to use a minimum level of force to stop the bad guy. The Castle Law brings it up a notch. The crooked cop reaction is a bit grey.
The problem is, players assume D&D justice runs under the Castle Law all the time. DMs don't assume that. Players are seldom told the laws of the land that their PC already knows, thus complicating matters.
The GM chooses whether to make a big deal over law infractions. Yiu can make the PC a criminal, you could make this a minor blip on his record. You could make it go away with a bit of gold.
The cops who came on the scene could have known who the PC was, saw the dead guy, and agreed he had it coming. The DM chose to make an issue out of it.
What all this matters is, because the DM is effectively choosing to escalate the severity of an alleged crime, he's choosing the direction to take the campaign.
Sure, it'd be nice to have the PCs not kill NPCs on a regular basis so they can continue on being heroes of the people. But you don't have to try to nail them with the law in every encounter where the NPC acts against the PC first.
Save law enforcement for situations where the PCs started doing something illegal. Like robbing people. Or breaking into buildings. Or attacking random people. The good guys get a pass on using lethal force when the NPCs try to do bad against them. Just like most action hero movies.
Thus, if you don't want the PCs killing people in town:
make sure an explanation of the basic local laws is part of the hand-out for the campaign. Covering use of lethal force is mandatory.
make sure you don't attack/do crime against the PCs, unless you don't mind some dead NPCs