Individual human beings are planners by nature; that is, we are goal-directed animals that have the ability to deliberately alter our present behavior in order to bring about a preferable future state of affairs. Social psychologists argue that although we are capable of altering our own goal-directed behavior for the sake of the future, we're not very good at it, and therefore we tend to live more in the present or near future. (There are evolutionary reasons for this that we explore later.) Living in social groups requires placing limits on at least some forms of individual behavior. All groups employ the use of painful disincentives (or sticks) and pleasurable incentives (or carrots). Legality and morality represent two different ways that societies and social groups to use those sticks.
Legality enforces rules, primarily, by punishing rule violations with painful dinincentives. Historically, societies have used physical pain (whipping), killing (hanging), deprivation of resources (fines), and incarceration (jail time). The degree of punishment has always been set in proportion to seriousness of the rule violation (or crime): "An eye for an eye and a tooth for a tooth." The rules that are monitored and enforced by any given group, reflect the values of the central planners. The Taliban's recent execution (by stoning) of a young couple for elopement, reflects the "value" that it places on the rules that govern marriage. The United States government still imposes longer sentences for drug offenders that use "crack cocaine" than for "powdered cocaine." (Don't ask me why!) Legality is obviously enormously complicated. Justice requires that rule violations must be deliberate, and therefore enforcers must decide the degree of voluntariness involved in the rule violation. Individuals that are declared "incompetent" are given lighter sentences, or placed under the control of psychiatrists rather than prison guards or executioners. The laws themselves are written by "lawmakers," in an obscure language that only lawyers can understand (sometimes they can't even understant it!), which means that questions of guilt or innocence are shaped by credentialized lawyers and judges, who control the processes of criminal justice. Some laws are so vaguely written that it's difficult if not impossible to decipher the lawmakers' original intent. Old laws are especially problematic. The courts generally rely on tradition to resolve these vague cases by referring to previous "legal precedents." In the end, judges and juries decide matters of guilt or innocence and the degree of punishment. Of course, the more laws that are being enforced, the more difficult it is for individuals to know what's illegal. And finally, most societies have processes by which convicted rule-breakers can appeal to another judge or jury. We can go on-and-on...but the point here is that legality is one way that human beings enforce rules that shape social behavior.
Morality is different. First of all, morality (by definition) is not enforced by any one single centralized entity: otherwise it becomes legality. Morality naturally arises from personal and group relationships. In it's purest form the rules of morality spontaneously emerge out of specific social contexts. We praise good behavior and blame bad moral behavior. Blameworthy behavior is discouraged by public sentiment, and not by physical threats to person or property. Public sentiment can be applied in various ways such as "labeling" the person that violate the rules, labels with negative connotations such as: whore, cad, tight-wad, drunk, or addict. Sentiment also includes punishing violations by individually and collectively treating that person as less valuable than others, including the practice of "shunning." The specific rules of morality tend to be rather stable because they get locked into bodies of tradition via teaching and learning. In fact, many individuals justify moral rules based on tradition alone: "We've always done it that way." But over the long run, moral rules evolve based on variation and selection. In the United States we do not regard having children out of wedlock as immoral or ilegal, although we do not think its very prudent. We certainly don't stone them. The advantage of relying on morality to insure social cohesion is that it does not require the formentioned expensive legal institutions: policemen, lawyers, judges, prison guards, and executioners. A moral society is "self-organized."
The nature of any society is based how much morality is monitored and enforced via legality. Minarchist libertarians, like myself, seek to limit the sphere of legality to harm to persons or property. Hence, limit legality to controlling murder, theft, and fraud. Communitarian societies tend to monitor and enforce much of their moral codes via the coercive power of legality, including