Okay, hopefully you've realized the title is a joke. I do not actually place a moral judgment on morals themselves.
Systems have this interesting tendency. The minute you get a pattern that is self perpetuating, well, it self-perpetuates. Surprise surprise right? If that pattern is a little robust to some random changes then when it hits a bump it changes a bit, and continues to self perpetuate. No magic is needed in this amazingly magical process. It's incredible. Once you get multiple of these systems competing for a resource, the most successful will survive, and the less will tend to die off. BAM we have creatures. Okay, so this is really just Darwinian evolution (or, technically, modern evolution, since it takes into account that such systems tend not only towards the winning strategy, but the winning robust strategy, which may include the ability transform the pattern itself in the future).
Now I've not been subtle about avoiding biological terms, and there's a reason for that. This is not a feature peculiar to biology, it exists in any system sufficiently complex to support such patterns. Physics just happens to be the basis for all such systems we know of, so not surprisingly some of the most fascinating and complex such patterns come in the form of biology. Most people by this point have heard of the idea of a "meme". A meme is a very simple concept, it is simply a self-perpetuating pattern of thought, capable of spreading between people. It is actually not quite fair to consider this under the terms of evolution, because it does not die and reform, it morphs as it is passed, so the die off doesn't work quite the same way. None the less it does play by some of the same rules. For example, the resource it uses is mind-share.
Memes are not so separable as biological bodies, it's hard to decide where one begins and another ends. Memes make up larger memes. This is true of course in the biological world as well. We contain Mitochondria. And we live within local ecosystems which in fact are self-perpetuating and self-stabilizing. Those make up the world, which by Gaia-Theory (which is now a theory) is itself self-stabilizing, for the same basic reasons. The obvious explanation is simply that species that consume a given resource do well when that resource is abundant, thus using that resource up, and pushing the global system away from that state. This happens on both ends and so you get a dynamic equilibrium.
Following our pattern of reasoning on complex systems, these systems "evolve" to survive. Humans are exactly such a system, and as a result have evolved the strong tendency to attempt to acquire things that further their own lives and, given an opportunity, for furthering the species. Simpler rules tend to be somewhat easier to maintain, and are more robust over a larger set of situations (I.E. they are not as prone to over-fitting, if you don't believe me go read some papers on AI and neural networks). As a result the overarching desires are fairly base, with a few slightly more general desires. The most basics are of course, food, water, the ability to breath, and sex, as these are required for quite a large number of species to survive they have had a long time to become ingrained are extremely robust and generally work out to be positive. The next most basic are things like protecting one's young, and possibly even some tribal instincts to protect kindred. Some species have migratory instincts the like that also lie on this level. I claim the level simply as a subject-to constraint. The second level is only full filled subject to the firsts fulfillment.
These ideas apply to memes too of course. As mentioned earlier there are sort of different levels of memes. A meme has desires in the sense describe above, as derived from being a complex self-perpetuating pattern. These drives might take the form of stopping people from changing the political situation which is in a Mame's favor for example. Please bear in mind that I'm not attempting to call a meme "intelligent" or give it a soul or anything like that. I'm simply noting that the physical reality that can be used to explain human desire also describes an analogous construct for memes. In the interest of Brevity though I will henceforth call this "desire", and the driving force behind actions towards a desire I will call "will".
So now we bring the world of memes and the world of human desires together. Humans compete for resources. Memes compete for humans. A meme exerts it's force of "will" through humans. Successful memes are those which can set up a human climate which allows the meme to spread quickly, and not get pushed out. In general a more stable human governmental type order is more favorable to the meme in power, since this gives it more power to organize people in it's favor, and against other memes. The meme currently in power is what people often call "society".
So what does society do? It encourages us to do things in it's favor. That is, we get punished for doing some things, and rewarded for others. I have found, through my life, that when I help others it works out for me. Being liked by other people, being seen as friendly and helpful, has given me a major advantage in life overall. As a result I've gotten more base desires. This training began when I was very young, starting from base and especially second level desires. Like skinner's rats we learn that something directly connected with a reward is good, and so we will attempt to reach that, even without knowledge of a resulting reward. It becomes a secondary reward. With proper training this can chain out quite far. And I see no reason why it cannot chain out into extremely abstract concepts.
So basically we are trained from an early age to be moral. Morality is the result of the interaction of our desires and the memes desires. Of course, society is made of lots of little, not completely homogeneous memes, down all of the way into a single persons thoughts. So we each are trained slightly differently. Sociopaths in some sense are simply people the meme failed to train, be it due to a physiological problem with that person, or a local disturbance the larger societal meme was unable to compensate for. School's purpose then is largely meme perpetuation. We are taught how to be good citizens, good members of society, how to serve the mime as best possible, and taught that in exchange we will be rewarded by society.
What is interesting about all of this is that successful memes all seem to have some characteristics in common. A meme needs the humans it has influence over to reproduce, thus Meme's encouraging reproduction are more successful. A meme needs those humans not to kill each other, thus memes discouraging killing within the society are more successful. A meme needs to squash other meme's which might take it's place, thus a meme which discourages other thought patterns is more successful. A meme which makes people more happy will be more successful, because it is able to control the structure more this way. If humans are unhappy they try and change the situation, which is inevitably bad for the meme in power
So we see that these are properties of all major religions. They discourage killing (except often of those of other religions). They encourage procreation. They discourage other religions (with the notable exception of some Buddhists sects). They involve parties every so often and encourage people to be "happy" and "fulfilled".
Properties of a meme induce a moral system in those people in which it has mind-share. So whatever properties a successful meme turn into somewhat universal moral codes. Like "Don't kill people", "Don't steal stuff", "Help out other people" etc. Obviously memes differ somewhat, and this is where morals differ, but the fundamental tenants of a Mimes survival make the resultant moral code surprisingly consistent.
So, who cares? Well, that's actually exactly my point in some sense. It doesn't matter whether you believe in morals or not. It doesn't matter whether you believe in emergent behavior or not. The system all comes out the same regardless, as long as self-perpetuating systems exist. In the words of XKCD "Science, it works bitches".
Some may find it repugnant to refer to "training" humans. I do not intend any negative connotations that may be connected to that word. It is simply the nice word. I intend no moral claims at all in this discussion. I merely intend to elucidate the idea that a belief in some true moral system is not required, the result emerges regardless. People often ask the question "If you don't believe in morals, why do you seem like a nice person?", or something else along those lines. My answer is that I was trained well by society. In some sense morals are the over-generalization of training. I take my past experiences of success with following societies desires, and I look at a possible action, and I judge the probability that some "immoral" act would overall work out in my favor fairly low, even if it's quite likely that I could get away with it. As part of my own belief system I accept this.
First, as I had vaguely realized but was glossing over - Meme's do not follow models of evolution. Because meme's do not multiply and mutate in the same way. They do mutate over time, but each instance is mutating itself all of the time, there's no discrete line between parent and child. What I did not know is that this actually significantly changes the mathematics of the modeling. I don't think it obviates my point, but it should be realized that viewing meme's like animals as a significant oversimplification. The claim that it's a self-perpetuating pattern running inside of some system, and thus has certain properties is of course still valid, as it does not invoke the biological models are more than an analogy.
It was pointed out to me recently that I am not saying morals are not necessary. This is really a matter of definitions. Obviously there is something which stops people from doing these things. If we call whatever that is a "moral" then I can no more deny them than I can gravity (given that gravity is defined as the force which causes things to drop). What I do not believe is required is a universal moral system, or even relativism in the classical sense.