The command in the Ten Commandments is to not murder, which is different from not killing.
God is the one who instituted the death penalty as capital punishment and governments, not individuals, have the authority to administer it.
Killing someone in self-defense or defending another is not wrong since it is usually accidental. Sometimes it's a byproduct of defense and cannot be helped.
It is still wrong. However, letting another person or yourself come to harm through your inaction is worse.
Here’s an example. You’re out one day taking your .300 Winchester Magnum for a walk when you spot a terrorist crouched beside a bridge in the distance. Through your 9x scope, you observe him trailing wires from a package he’s laid under the bridge support. Looking up the road, you see a bus from Mother Benevolence’s School for the Blind approaching the bridge. It is an easy shot to take out the terrorist.
If you kill the terrorist, it is a premeditated act — a murder. It is wrong. If you fail to act when it is within your power to stop him, he kills a bus full of blind children. That too is wrong.
Your choice is between two wrongs. But God put you there that day for a reason.
Which act would God forgive?
Trick question. He would forgive either of them if you acted with a pure heart. The decision — and the motives -— are yours. No one said it would be easy.