Much confusion has arisen from the misleading translation of Exodus 20:13 that occurs in most English versions. The Hebrew original uses a specific word for murder (rasah) in the sixth commandment and should be rendered “You shall not murder” (as opposed to many English versions which read “kill”). This is not a prohibition against capital punishment for capital crimes, since it is not a general term for the taking of life, such as our English word “kill” implies. Exodus 21:12, in the very next chapter, reads: “Anyone who strikes a man and kills him shall surely be put to death.” This amounts to a specific divine command to punish murder with capital punishment, in keeping with Genesis 9:6: “Whoever sheds the blood of man, by man shall his blood be shed; for in the image of God has God made man.”
Violence and bloodshed are occasionally mentioned in the record of man’s history throughout Scripture, but never with approval. Yet there were specific situations when entire communities (such as Jericho) or entire tribes (such as Amalekites) were to be exterminated by the Israelites in obedience to God’s command. In each case these offenders had gone so far in degeneracy and moral depravity that their continued presence would result in spreading the dreadful cancer of sin among God’s covenant people.
–Encyclopedia of Bible Difficulties