Morality is a product of evolution, it’s a characteristic that all social animals have, and that solitary animals do not have.
The foundations of morality are based in our instincts, social moral codes are built on top of these more basic, instinct based, codes.
People who look at current liberal moral codes as being superior to past, typically stricter, moral codes; who think that morality has, in some objective sense, improved or gotten better, don’t get that these changes in moral codes are simply a product of changing technology and greater wealth, that with the loss of that wealth and technology, stricter moral codes would reappear.
In wealthy societies whose inhabitants perceive little threat to themselves as a whole or as individuals, those strict practices that worked to unite a society through common beliefs and practices (beliefs and practices that in themselves created a clear differentiation between each society and other, outsider and potentially hostile, societies), weaken, as the survival pressure to maintain that ridged unity are not so great.
Greater wealth also means that the cost of expensive and destructive practices by those within the group are more affordable to the group as a whole, for this reason divisive and destructive acts, and those who commit such acts, are more tolerable to the group as a whole.
A useful illustration of how strict adherence to accepted codes can serve to strengthen a social group can be seen in military discipline, where the groups survival is enhanced through sacrificing individualism. Military units that lack strictly enforced internal moral codes don’t survive unless they’ve significant advantages in other respects that offset this lack of enforced cohesion.
Within a society there are two groups of individuals serving different roles that in combination enhance the survivability of the group. The first group is the high status establishment leaders, those representing the status quo of the group, are typically more wary of the threat posed by both insider and outsider groups to that status quo, the second group are those wishing to move up in the pecking order, looking for opportunities to advance their own status, this group is less focused on potential external threats to the group, in fact because the former group uses the external threat to justify the status quo, the second group rates that threat as less significant.
It can be seen that religion is a useful tool in providing a group with many characteristics advantageous to survival, it provides defined common moral codes, codes that differentiate it from outsider groups, and moral codes that, because of the continuity of leadership policies provided by a deity, provide stability. It’s also advantageous if the religions moral codes are appropriate for the environment the followers live in.
All morality that runs deeper than social customs, morality that is always the same throughout human history no matter what cultures might exist, is based in human instincts. Other sentient creatures, for example, those in which, for biological reasons, the female parent eats the biological father as part of the reproductive process, would have their own moral codes that are independent of what humans might think is “right”.
In times of bounty a society as a whole may be better off accepting greater diversity amongst it’s members,taking multicultural societies as an example, I think in times of prosperity they can be stable, but in times of hardship it’s very easy for rabble-rousers to create division. In times of extreme hardship societies fragment and collapse, and cultural differences are one of the first fault-lines to split open.