Thank you for the thought-provoking question.  We presume you are specifically referencing Ex 20:13  Thou shalt not kill; as the basis for this question.

We must look at the entire law to understand God’s justice. If you read the details of the law given in Exodus 20-31 (especially chapter 21), we see that there are death penalties associated with certain actions. These penalties required the people of Israel to carry out (execute) God’s justice.  So if a man purposely kills his neighbor, that man was put to death by the people of Israel.  If all killing (regardless of reason) was against God’s law, there probably would not be a death penalty in His law.  So we can say that under God’s law, depending on the circumstances, killing is permitted.

Recall in 1Samuel 15, God told King Saul to utterly destroy Amalek – including women, children, and animals (verse3).  Saul disobeyed and saved the king and the choicest animals.  His disobedience caused God to anoint another king – David.  David was also tested in similar fashion, to slay God’s and Israel’s enemies.  But unlike Saul, David was obedient to God’s word and as a result, he and the nation were blessed.  Remember that these were God’s enemies, not specifically David’s.  God passed His righteous judgment upon them and asked David to execute that judgment.

When David caused Uriah to be killed, he did it for personal gain (2Samuel 11).  This killing was against God’s commandments and David was punished (although God showed great mercy and forgiveness in NOT requiring the death penalty for David).

So is killing contrary to God’s commandment?  We answer – no, there are times when it is permitted. 

God says “vengeance is mine. I will repay” (Romans 12:19).  God’s justice is first and foremost, and sometimes He uses His servants to carry out that justice; sometimes God, himself, executes it (Exodus 12:12).  As with the case of David, it seems that the motivation for killing seems to be the primary factor of whether or not it violates God’s law.  If killing is required to execute God’s righteous judgments, then obeying God is the duty of His servants.  If God has not judged, and the killing is for personal gain or execution of man’s judgment, then it violates God’s law.