“Thou shalt not kill” is taken from Exodus 20:13 in, e.g., the KJV of the Bible. A better translation of this verse is “You shall not murder”.1 The Law of Moses, from where the Ten Commandments are taken, didn’t outlaw all forms of killing. For example, in some instances people were allowed to kill other people: see Numbers 35:18, for instance, where it says, ‘The murderer shall be put to death’ — i.e., under the Law which God gave to Moses, murderers were to be killed. So, “Thou shalt not kill” doesn’t refer to all killing generally (for one thing, it excluded capital punishment).
In fact, outside of the few times it’s used to refer to capital punishment (which, as we’ve seen, was not a prohibited form of killing), the Hebrew word that’s translated as kill in the KJV of Exodus 20:13 is only used in the Bible to refer to times either when someone accidentally kills another (e.g., Num. 35:11), or when someone kills on purpose (e.g., Num. 35:16).2 It is never used in the context of war, for example. So, again, “Thou shalt not kill” is not a blanket prohibition on all instances of killing. It is just referring to times when someone kills another on purpose — i.e., when they murder someone.3
This, to some extent, helps us understand how God could say “Thou shalt not kill” and also command his people to kill other people (e.g., 1 Sam. 15:3): “Thou shalt not kill” is not referring to this type of killing. The killing that God commanded his people to perform on other people was more like the “capital punishment” type of killing, where God was punishing people for the evil they had done. See, for example, 2 Samuel 15:2-3:
Thus says the LORD of hosts, ‘I have noted what Amalek did to Israel in opposing them on the way when they came up out of Egypt. Now go and strike Amalek and devote to destruction all that they have. Do not spare them, but kill both man and woman, child and infant, ox and sheep, camel and donkey.
Here the people of Amalek are killed in punishment for the bad things they had done in the past.
What about us?
Leaving this aside for a moment, currently God has commanded his people not to kill at all (no murder, no “capital punishment”, no war): see, e.g., Romans 12:17-21. Rather, they are to love their enemies as themselves (Mat. 5:44).
1. See, e.g., most modern translations, e.g., ESV, NASB, NET, NIV, GNT, HCSB, NCV, NLT, NRSV and even the NKJV.
2. And once when it refers to a lion killing someone. See the following verses: Ex. 20:13; Num. 35:6,11-12,16-19,21,25-28,30-31; Deut. 4:42; 5:17; 19:3-4,6; 22:26; Josh. 20:3,5-6; 21:13,21,27,32,38; Judg. 20:4; 1 Kings 21:19; 2 Kings 6:32; Job 24:14; Ps. 62:3; 94:6; Prov. 22:13; Isa. 1:21; Jer. 7:9; Hosea 4:2; 6:9.
3. Obviously, it doesn’t included the times when someone accidentally kills another. The law didn’t say, “You shall not have an accident”. So “Thou shalt not kill” is limited to murdering someone.