"That which is necessary is legal" is a doctrine practiced by sane states, so I would like to believe.
What has been said about "That which is necessary is moral"?
There is an inherent back pressure that comes from a doctrine like this. "That which is necessary is legal" presses back on the definition of "necessary." If there is a strong desire for an act to be illegal, there will be a corresponding strong desire for that act to be deemed "not necessary."
If you apply this logic to "That which is necessary is moral," the backpressure gets extraordinarily strong. Questions of "is it necessary to remain alive?" arise. Consider the Samurai: in many situations the only moral course of action they had available was to commit ritualistic suicide. They did not have the luxury of assuming that living was a necessity.
However, it does lead in an interesting direction to explore. This quote feels very similar to the attitude that there is always a moral path to follow, no matter how far one has strayed. Doctrines can be slippery at times.
You have to be a bit careful in philosophy when tossing around the word necessary. Philosophers, like kleptomaniacs, take things literally. :)
However, in context, "That which is necessary is legal", or Quod est necessarium est licitum is actually a tenet of what's called the necessity defense that is recognized as common law and is in most states' statutory law. And what it means is:
Sometimes, in a particular situation, a technical breach of law is more advantageous to society than the consequence of strict adherence to the law
Something we all commonly encounter on the news without really considering it too often. An example - killing in self defense. In most examples of the necessity defense, an argument based on common good, or significant, unavoidable harm is given as the basis for necessity.
So, your question essentially boils down to this (if I understand you correctly):
Do any theories of morality have a similar clause: At times, doing the most moral thing requires acting immorally?
The answer is, yes, though there might be some wiggle room in terms of what's defined as moral, immoral or amoral on a case-by-case basis. The necessity defense would fall under the umbrella of utilitarianism in terms of ethical theory. An oversimplification of utilitarianism might be stated as:
"One should do whatever maximizes the total or average welfare of society"
Or, using the example of self-defense, "that which is necessary, is legal/moral" could be restated as:
"when one is facing imminent harm, it is in society's total or average best interest that one defend one's self with equivalent force and in such circumstances killing may be considered a moral or amoral act."
Hope this helps. -Wah
Emile Durkheim, a prominent French sociologist and philosopher, disagrees with you, and the original Roman saying:"Deviance serves major functions to society according to Durkheim; it affirms our cultural values and norms and clarifies moral boundaries. It also promotes social unity and encourages social change. A society without crime is an ideal place for many, (so they may think.) However, a society without crime is society without any progress". So crime is necessary, and illegal.
The same applies all the more to morality. As St.Augustine put it, "the canvas of creation requires both the black and the white paint". The evil is immoral, but it may be necessary, to provide "diversity" or free choice for example. See Is God either immoral or not omnipotent? and How does free will defense of God's benevolence work?
Whether morals are absolute or relative, as far as we know they are relevant only in a human context. We don't expect nature to "act morally", nor have other sentient beings been found from whom we could expect so.
But to be able to act morally, humans need to live, and living entails certain necessities. Thus the relationship between morals and (vital) necessities should be described not as necessity implying morality, but as "necessities being satisfied" being a requirement for concepts like morality and ethics to even make sense.
I always hate introducing folk-tradition stuff here, because I cannot attribute any of it. But this seems relevant to the question in a broad sense. This basic notion seems to have been known to Kant, since he uses one branch of it "ought implies can" in lectures.
There is a sequencing to the basic modalities, sometimes expressed in a little box containing the modal and mode-like verbs
ist -> muss -+-> soll --> darf -+ | | +-> will --> mag --+-> kann --> weiss
Or in English:
consistent -> must -+-> should -> may --+ | | +-> will --> might -+-> can --> conceivable
It kind of gives an informal excuse for the odd relationships between the conjugations of these specific eight verbs, and it captures some essential concepts of the relationships between different kinds of modal statements.
In every case "box" --> "diamond"
consistency -> conceivability (= non-inconsistency) must -> can (= not mustn't) should -> may (= not shouldn't) will -> might (= not won't)
And the force of the modal construction comes in three tiers:
In branch of concern to Kant is "soll -> darf -> kann -> weiss". In particular, it is unfair to require and misleading to permit what is impossible. And it is impossible to carry out what is not conceivable. The former two have application primarily in law, and the latter with how one handles children or those of diminished capacity.
The relation between needs and public policy is not straightforward. Discussions about what people "really" need are hard to settle, and even if people agree that X is needed, a lot of questions concerning how to satisfy X and how important is to satisfy it, given that we also need A, B and C, have to be answered. Also, in some situations, there might be a conflict between satisfying need X and being just, brave or honest, and it's not clear that we should always put needs on top of these other values.
Since your question is tagged as a reference request, I highly recommend David Wiggins' "Needs, Need, Needing", available here, if you wanna delve into the topic of needs, "Claims of Need", also by Wiggins, is an excellent paper, but is not available online.
Your question is too open ended to give a meaningful reply. In a sense, every major brand of moral theory tries to tell you what is needed to make a better world, or to do the right thing, or to be a flourishing human being; but the notion of need seems to acquire meaning only after we decide which of these things are really worth getting.
That which is neccessary is moral
This question can only arise in a situation where what appears to the right course of action is against normative moral considerations.
It's an appeal, in a sense to legislate new moral norms.
Kants answer to this is his categorical imperative; which is that a possible course of action in a situation is if this action can be considered as a general maxim of moral conduct; that is one thinks of oneself as a potential legislator for the community.
It is as though one submitted the situation at hand to some impartial judge who then legislates the possible lines of action for this and analogous situations binding on the whole community.
It's easy to see that this cannot go against what laws are already held.
It maybe this impartial judge might demonstrate that the situation allows of actions that do not go against already established norms, but that this might require more work; or that it actually opens up the possibility of a new positive norm that is to be welcomed rather than to be deterred from; or most likely it requires a minor modification.