Exodus 20:13 reads, "You shall not murder." Not all killing is murder.
The dictionary definition of murder is: the unlawful premeditated killing of one human being by another.
If God's people are under God's law and it is a commanded to kill to save God's people, then it is not unlawful.