The answer to that is found in the distinction between the 4th and the 5th commandments. In the 5th commandment we are told not to murder, nor to do anything that hurts or harms our neighbor in his body. But as Luther points out in the Small Catechism, "Neither God nor the government is included in this commandment . . . God has delegated His authority of punishing evil-doers to civil magistrates in place of parents . . . Therefore what is forbidden here applies to private individuals, not to governments."
According to the 4th commandment, which establishes parental authority and all other forms of authority, God acts through civil officials to execute judgment on wrongdoers. Though this authority is sometimes abused, God nevertheless is the source of the authority and is the One who is behind all proper exercises of it.
Romans 13 says, "Let every soul be subject to the governing authorities. For there is no authority except from God, and the authorities that exist are appointed by God. Therefore, whoever resists the authority resists the ordinance of God, and those who resist will bring judgment on themselves. For rulers are not a terror to good works, but to evil. Do you want to be unafraid of the authority? Do what is good, and you will have praise from the same. For he is God's minister to you for good. But if you do evil, be afraid; for he does not bear the sword in vain; for he is God's minister, an avenger to execute wrath on him who practices evil. . ."
Therefore, when a government executes a criminal worthy of such a punishment, or when it wages just war, particularly in defense against foreign aggression and threat, it does not sin, for it is acting as God's agent to punish evil and to protect its people.