There are three fonts of morality, three things only that can make a knowingly chosen act of a human person moral or immoral:
It is always wrong to act with a bad intention, that is, with an immoral intended end. The intention is the reason or purpose which motivates the act; it is the end in view.
It is always wrong to knowingly choose an act which is inherently ordered toward an evil moral object. The object is the end toward which the knowingly chosen act is ordered, by the very nature of the act. Hence, if the object is evil, the act is intrinsically wrong; it is evil by its very nature, since its nature is nothing other than its ordering toward an evil end.
The intention is the end chosen by the agent, the person who acts. The object is the end inherent to the act itself.
It is always wrong to act when you reasonably anticipate that your act will do more harm than good. The circumstances of an act is the totality of the foreseeable consequences of that act for all persons concerned.
Even if the intention is good, and the act is believed to do more good than harm, the deliberate choice of certain kinds of behavior or certain specific acts — intrinsically evil acts — is always immoral, quite apart from a consideration of the intention for which the choice is made or the totality of the foreseeable consequences of that act for all persons concerned.
Striking a population center, that is, directly targeting civilians in warfare, whether with a nuclear bomb, or with artillery or conventional bombs, is intrinsically evil. It meets the definition of murder and of mass murder, regardless of its alleged usefulness in winning a war
Pope Saint John Paul II, in Veritatis Splendor, gives examples of intrinsically evil acts:
“Whatever is hostile to life itself, such as any kind of homicide, genocide, abortion, euthanasia and voluntary suicide; whatever violates the integrity of the human person, such as mutilation, physical and mental torture and attempts to coerce the spirit; whatever is offensive to human dignity, such as subhuman living conditions, arbitrary imprisonment, deportation, slavery, prostitution and trafficking in women and children; degrading conditions of work which treat laborers as mere instruments of profit, and not as free responsible persons…”
So arbitrary imprisonment is intrinsically evil, and therefore cannot be done for a good intended end, even in dire circumstances.