According to Rick Garlikov, 'some laws are managerial or administrative in that they institute behavior for procedural purposes that could equally well, from a moral or socially useful point of view, have been written in a different, or even opposite way. The common example is traffic rules about the side of the road on which one is to drive. Apart from consistency with bordering neighbors (especially for safety purposes of driving across borders and in neighboring countries), it does not matter from a moral standpoint which side a country (or a set of neighboring countries) adopts, as long as the choice is made among equally right (e.g., safe) options, though once a side is chosen by law, it is generally prudent, and morally obligatory without some good reason to the contrary to abide by the choice. These laws are not based on morality, in terms of their specifics. They are moral because they are a way of promoting social benefits of a certain kind in an optimal way.
some laws are immoral, usually because they are unfair but sometimes because they are counterproductive or harmful; in some cases, egregious and reprehensible. There have also been government programs set up by law that simply mistakenly harmed the people they were intended to help, such as aspects of the welfare rules that ended up trapping people in poverty rather than assisting them to escape it.
laws concerning evidence and procedure in courtrooms often lead to acquittals of obviously guilty defendants, and sometimes to convictions or continuing sentences and punishment of known or likely innocent ones. There is no reason to believe that just because a law passes, it is for the best or that it is right or moral, even if the people passing it think it is. If one were to be charitable about legislators, one might perhaps be able to argue that they pass those laws they believe to be right, whether those laws actually are right or not, but there is sufficient evidence legislators will often pass laws for political reasons -- to win or keep political support from those whom the law favors or to whom it panders -- even though they know the laws are bad or wrong. Either way, however, sometimes bad or immoral laws get passed which are perfectly legal.
Not all morality is enshrined in law because law is in a sense "incomplete". Many unfair and wrong business practices are not anticipated and therefore not made illegal until someone invents and uses them in a way that clearly mistreats others. These practices are wrong and immoral from inception, but not illegal until law "catches up" to them. In a sense morality is "complete" and applies to all acts, but the law typically is "incomplete" and only applies to behaviors legislation has already addressed, or that the courts can interpret to have been addressed by implication in existing law. Law has to be "invented" or manufactured; morality only has to be recognized. And in the creating of specific laws with specific wording, loopholes creep in because it is difficult to predetermine and specify those and only those acts intended to be covered. Morality does not have loopholes. It is probably impossible to make a complete set of laws that anticipate, enumerate, fully describe, and forbid every possible specific wrong behavior.
Not all morality should be enshrined in law, because enforcing some morality would be far worse than not enforcing it. For example, even if it might be wrong for someone to lie in bed an extra half hour rather than having a good breakfast or getting to work on time, or even if is wrong for a child or husband to leave dirty clothes on the bed or floor, or even if it is wrong to break a prom date at the last minute for no good reason, those transgressions are not grounds for sending in the police.
Liberty and autonomy are important values and they sometimes require letting someone make a mistake or do the wrong thing -- as long as the wrong that is done is not so bad or so costly that civil society has a legitimate interest to prevent it. There are sometimes disagreements about where the line should be drawn, but there are clearly some actions where autonomy is more important than being forced to do what is right by law, and there are clearly some actions where prevention of harm overrides autonomy and liberty.
people disagree about moral issues. People also sometimes disagree about which laws should be created or kept, sometimes on moral grounds, sometimes on merely prudential or practical grounds where different consequences are predicted. When moral viewpoints conflict or are contradictory, law, unless it is to be contradictory itself, cannot reflect the morality of different people. Constitutional rights will sometimes even prevent law from conforming to the wishes of a simple (even substantial) majority of people or their representatives. How can laws conform to morality when people disagree about what is morally right or wrong, or when their collective wishes are "thwarted" by the Constitution and by whatever minority is sufficient to prevent amending the Constitution? "Morality is subjective." But disagreement can be about objective matters as well as subjective ones, when it is difficult or impossible to know or conclusively demonstrate the correct answer. Disagreement, even unresolvable disagreement, does not necessarily make an issue subjective.
it is often normal for people to believe that the status quo and traditional practices are what is morally right. It often is very difficult, especially for those who benefit from current practice, to notice or see there is something wrong with it, let alone agree with that assessment. Hence, they tend to see efforts for reform as unnecessary, destructive of a well-functioning system and social order, or even morally wrong. It is one view of law that it tends to favor existing power structures and relationships, not necessarily or not only through some sort of Machiavellian attempt to maintain power through evil means, but because existing systems seem to work well (enough) and because they seem psychologically to be normal and reasonable, especially to those in power.
In spite of all the above, there seems to be some relationship between law and morality, or at least it seems there ought to be because we talk about unfair or unjust laws, laws that are immoral, laws that ought not to be obeyed or enforced; and we typically do not mean just that they are unconstitutional, but that they are counterproductive to their intended purpose or that they are bad or harmful or morally unfair or unjust laws.
Most of the major purposes of the Constitution are to help us be law-abiding so that we are a better country, not just an orderly or merely obedient or efficient country. Hence, it would be remiss, and wrong, to make laws or to try to interpret laws in court, and deriving their legal authority ultimately from it) without any regard to their moral meaning, moral significance, or moral consequences insofar as these impact justice, liberty, general welfare, the common defense, and domestic tranquility. And it would seem that any constitution without a moral purpose would be merely an arbitrarily pointless or meaningless formal document establishing an equally pointless formal system. There could be such a system of law and those who pronounce judgments, but it would not be a system of "justice." And it would not, except by chance, promote the general welfare or any other moral virtue.
Given that some laws are immoral, that some laws reasonably are neutral with regard to morality, and that there are institutional limitations to enforcing some aspects of morality, the interesting question should be, not what the relationship is between law and morality, but what it ought to be. It might be important to obey some bad laws, under certain circumstances, until they can be changed because the fairness and consequences of doing so might outweigh the justice or consequences of moral disobedience in those cases. If, for example, some system is established for distribution of resources that is arguably not the best system, but which works to some extent, chaos might result in trying to implement a better system on one's own or in some fragmented or rebellious way. In the driving case, for example, even if you knew it would be far safer for everyone to drive on the other side of the road, and even if you worked diligently to change the side of the road your country required drivers to use, it would be madness, and morally wrong (because it endangered people unjustifiably), for you to simply begin to drive on the opposite side on your own. Nor would it likely be safe for the legislature to pass a law requiring an abrupt change on a certain date, if that does not allow time for changing road signs to the other side of the road or doing any of the many other things that would be required to make the switch feasible. Or even if it makes more sense to use the metric system than the English system of measurements, one cannot just switch to metrics overnight. Bad laws and bad administrative practices, though, do not justify their continuation without remedy just because some remedies might be difficult. Optimally fair and beneficial remedies to achieve optimally beneficial and fair laws should always be the goal. Doing the morally right act is always at least our prima facie obligation. Obeying some bad laws in some circumstances is a worse breach of morality and duty than obeying them until they can be changed. And in those cases, the law ought not to be obeyed. A law, for example, that required you to take the life of an innocent person ought not to be obeyed if there is not time to change it first. That is not something you follow and then change afterward.
In any practical case people may disagree about what is tolerable or not, and that disagreement should be worked through, in an attempt to resolve it, in a morally acceptable and reasonable way. Here, it' not about how to deal with civil disobedience based on genuine disagreements of conscience, but presumably there should be some reasonable and fair way to deal with such cases. It should also be understood that even where there are grounds for civil disobedience, there can be wrongful acts of civil disobedience, such as, in some cases, assassinating those who disagree with you over an issue that does not justify such murder. Morality is not only relevant to the content of specific laws but it is also relevant to the proper way to make law and to take into account differences of conscience by reasonable people. There needs to be some sort of understanding about what forms of disobedience may be acceptable when there is serious disagreement among the consciences of reasonable people.
It seems to me then that what gives law its authority is its conformity to morality, in that correct laws need to be obeyed because they are fair, just, and beneficial under the conditions and circumstances in which they exist and apply. Insofar as the legal act is the right act, one should do the legal act just because it is the right act.
And what makes people voluntarily obey laws when they do is either that they believe the law is in conformity with what is morally right (or if it is a procedural law, they believe it does not conflict with what is right) and is just and beneficial, or they believe that the particular law at issue is not so bad, even if wrong, that it is justified to break, either because breaking it would cause more harm than not breaking it or because breaking it would risk undermining the general cultural respect for law. But many morally good people will disobey laws they think are very wrong, either in a form of civil disobedience, or in order to get away with it (as in speeding on a long straight, flat, open road with no traffic, because they believe the law does not have moral authority then. And if the government passes sufficiently many bad laws, or sufficiently egregious laws, it will lose obedience by rebellion or revolution, because citizens will believe (sometimes correctly) that the laws and the government are too immoral to have any authority that deserves their obedience.
It, of course, is always possible that people will obey the bad laws of any government that has policing resources strong enough to force such obedience out of fear or risk of punishment or reprisal. But that does not give law authority; not rightful authority anyway. If we were to call that "authority" then we would have to say that as long as they go unchecked, playground bullies have the authority to take other children's money or lunches. They have the power, of course, but not the authority. The conventional wisdom is that one should obey the law until one can get it changed. That is a moral contention, which has some, but not complete merit. There are some laws and rules that are so egregious or so (potentially) harmful to obey, and sufficiently less harmful to disobey, that it would be morally wrong to adhere to them until the law can be changed. The example above is of having to execute a person known to be innocent simply because there might be no formal mechanism in law to prevent the execution. Or having to prosecute someone harshly for conscientiously and correctly disobeying an unjust, but legal, law.'
(From Morality and Law by Rick Garlikov at garlikov.com)