The above post started to show that Catholic morality distinguishes between killing and murder. When Jesus summed up the commandments, he always cited #5 as prohibiting murder, for that is what it actually says. Our “Thou shalt not kill” is more of an easy shorthand than an accurate representation of the injunction. Basically, murder is the deliberate taking of innocent life. Killing is the taking of life. Killing can be morally acceptable when done in the proper circumstances and/or with proper authority.
For example, one may kill in self-defense so long as one is trying to use proportionate means to repel an attack. The object is to try not to kill if possible, but killing in self-defense is considered to invoke the principle of double effect: the intent was to protect oneself, an undesired side effect was the taking of the aggressor’s life.
Another instance of acceptable killing is the use of the death penalty. This killing requires not only sufficient grounds but also proper authority. For instance, if I came across a notorious perpetrator of genocide I would not be justified in executing him simply because I am sure any court that got his hands on him would do the same. Only the state has the authority to execute (see Rom 13).
One more most common instance of morally licit killing is killing in a just war. Not only is it morally acceptable to kill an agressor in war, the state (and those who serve in its military - note, another instance of proper authority) has a DUTY to wage war when war is justified. I bring this up because you talked about how you would not (or would hope not to) kill anyone if it could be helped. But in cases where you have a duty to defend others, it would be sinful NOT to respond with lethal force if that were necessary to repel an attacker.
I don’t think it’s entirely clear to say there are instances where individuals have a moral duty to kill (because that leaves out the nuance of ensuring proportionality of punishment/defense), but that’s basically what it boils down to. If a policeman or soldier stands by while others are killed, he may not have murdered them but he bears guilt for their deaths. Aquinas deals with just war not under the virtue of justice but under the virtue of charity. To fail to use force when necessary is above all things to fail to love.