Thou shalt not kill is for people who live in the community, and it is there for the protection of the community, and reverence for life, and the author of life, God.
Soldiers, on the other hand, place their lives on the line in order to defend and protect the community from those who would invade, commit rapine, pillage and plunder and inflict suffering. In the name of the community at large, the polity (YOU) the government authorises soldiers to kill in a theatre of war, only. If soldiers kill outside their proper theatre of activity, the War Zone, then they are up for criminal charges, and this has happened quite often (especially recently) ... the prosecution of soldiers for offences against humanity outside their proper place of battle.
So you will understand that there is a text, and a context for the commandment. It is there to reverence life, all life, and to point to the author of all life, God. However, a nation is allowed to defend itself, and if must needs be, death occurs in a specific theatre of human activity, for which they are trained, armed, and have strict rules of war to abide by.
- Soldiers can be religious. The commandment is better translated "Do not Murder" - distinguishing accidental killing (what the law would term manslaughter) from deliberate killing. Some religions teach that there can be a just war. There are also situations in the Bible God tells his people to kill others because of their sin.