The important thing to realize, as Daniel Giron has pointed out, is the essence of the question 'What makes a thing necessary?' A thing can be necessary for a certain end while not being morally fruitful, nor right, if such a thing were to be acted out.
Just to give one example, consider the idea that it is necessary to kill a dog if you desire it to be dead. As you can see, believing that the act of killing the dog is therefore morally acceptable is foolish. This is because it is the moral quality of the end that determines a thing's moral reality.
The question to truly be asked is rather 'What composites an end to be morally right?' The answer to such a question is always the same; if an end brings about a greater good it is always justified. But here is where the problem becomes somewhat more interesting; a person can believe that an end brings about a greater good when it truly doesn't. This is perhaps most seen in the past century. This century's mass genocides that have taken place in the name of the 'greater good' are rather obviously not taking place for any 'good' at all. Such events occur only to satisfy what morally corrupted man believes to be the greater good.
This misunderstanding of terms in reality can also be applied to what is meant by 'necessity' itself. Often times a moral end can appear to only be achieved by one necessary path when in reality there are other more positively moral roads that can be taken to achieve such an end. An absolutely morally necessary act, thus, is only necessary insofar as the end cannot be achieved without such an act. But a thing can nevertheless appear necessary to a certain individual, and so be necessary granted the considered conditions.
For example, consider a starving family. There is a possibility existent that in some capacity this starving family could be fed by charity, but this lies only as a potentiality until actualized. As such, it is the parents' obligation to seek themselves for food. The moral necessity of the parents preserving life is not absolute (since there is a potentiality that food could be given to them by another) but it is personal (since this potentiality has the potential to not be fulfilled without personal will). So the question than, with the Starving Family Moral Dilemma, is whether theft of food is morally necessary. The answer in short, given that the theft occurs in such a way that food is taken from those who have plenty themselves (aka not taken from those also starving), is yes, not absolutely but personally.
This is because the moral obscurity of whether life can be preserved without personal will verifies action of personal will, so long as such will does not take life itself (and even this understanding can have certain exceptions, an example being the defense of life against a person who's life is a threat to other life). To phrase it another way, the Divine Order wills that theft in this case be permissible since its end is of moral worth.
Hence St. Aquinas states the following:
For instance, a man may have another's goods, whether in money or in kind, either because he has stolen them, or because he has received them on loan or in deposit or in some other way. In this case a man ought to pay what he owes, rather than benefit his connections out of it, unless perchance the case be so urgent that it would be lawful for him to take another's property in order to relieve the one who is in need.
But even Aquinas has a difficult time answering the obscure questions that come when theft occurs upon those who are in need themselves. In other words, when one starving family encounters the food of another starving family. These sorts of questions require an entire background of moral theory that is best researched independently.