How all might have begun or a short (hi)story on religion.
In the beginning there was the community and of cause it had to have a fairly big size to keep going in a hostile environment as well as to evade the fatal results of inbreeding.
To keep up in a hostile environment it was essential that each member had to be placed at tasks and responsibilities where it's abilities could add the most to the communities survival and/or prosperity. But to figure that out it took a lot of experience so that to decide was dedicated to the council of (experienced) elder as were all decisions encompassing the hole community.
Now in the course of development a lot of different rules evolved just according to the fact that obeying them just proved to secure the communities survival and/or prosperity.
Of cause injuring or even killing a community member would cause to weaken the community and was therefore not to be allowed. The same applied of cause to members of neighboring communities because then they might refuse to help in times of emergency.
For similar reasons tending the sick, wounded or ill became commonplace.
These elder who no longer had the strength needed for every day struggle for life turned out to be the best choice to educate the young and thereby develop more profound skills at the intellectual level.
Feeding that back to the community made then decisions possible to decide to sustain members who were deemed to be successful when they wanted to devote some of their time to improve hunting techniques or to create more efficient tools etc. etc..
A lot more of rules had developed but I may just point out one more: If you can help someone in need so do it because it may come to pass that in return you may depend on his help.
In short, mankind had set out on it's path and made good progress in it's development.
Now and then it happened that circumstances made it happen that a community left that common path and developed a hierarchical social order. But as long as the combined abilities of the community were needed for survival they would not have lasted long.
But when development had reached the point where mankind controlled it's environment to an extend it could no longer pose an imminent threat to survival that changed too. Now we had a situation where two different kinds of social entities could be found, the 'traditional' communal ones and some 'exotic' hierarchies.
And even as the separate development of these different social entities was still in it's infancy the differences could hardly be greater.
Just to put it somewhat shorter I will use the term communes for the traditional social entities and the term tribes for the hierarchic ones.
Let me just point out the main difference:
As I pointed out we are now looking at a time where the environment no longer poses an imminent threat to survival though there is still some environmental pressure on survival but that lessens with ongoing development.
Now that frees rising resources and while these are used to thrive for overall prosperity in the communes the lions share of these are spent on gaining or defending rank in the tribes. Concerning this it is fairly easy to see that leadership by competence is more efficient than leadership by rank.
On the long run the tribes seemed doomed to lose this kind of competition. So sooner or later the tribes came to see the communes as an imminent threat to their existence. Maybe some of the tribes gave up and joined neighboring communes while others tried it the other way round and tried to gain the prosperity owned by neighboring communes by conquering them. Unfortunately many of these attempts were successful. At a closer look the communities did hardly have a chance because their rule forbade personal combat while exactly that had become an essential part of the tribes culture as a means to define, gain and defend rank in society.
But on the other hand the tribes were by far outnumbered from the outset so it was clear they had a really long way to go to prevail. Having found the true law of nature - so they thought - that the strong always prevails, made them confident that their hierarchic society system had to be the superior one. Sure a fair number of them fell to the trap of that thought by conquering too fast so that in the end the number of the ruling class was too low to keep in power and so they got assimilated into the conquered communes.
Other tribes of cause learned that lesson.
But there was something these tribes could not comprehend. Being superior in any respect to neighboring communes - so they thought - they were no match to these communes in any respect to development. But of cause as well as the communes were unable to accept the idea of combat (including injuries and death) as being consistent with what they perceived as sort of universal (OK, at least human) rules of conduct, the tribes were unable even to think that any other form of social organization might be more efficient than their 'superior' hierarchic system.
That led inescapable to the conclusion of something supernatural being at work here. So they set out trying to make that supernatural thing work for them too. They compared their own live stiles with that of the communes and found a main difference in the use of leisure time and the dominating set of rules governing society.
The latter of cause could not be causing the effect.
Within their own society most of leisure time was used on perfecting skills needed with respect to rank. In the opposite in the communes leisure time was filled with song, music, dance and feasting. So the framework for something new was set and religion invented. The communes rules were taken, worked over by adding rules that makes a hierarchical social order mandatory - to say they were given by a supreme god might be sufficient - and while they until now just reflected the learnings of millennia of development and were hold to be somewhat universal to mankind now they were tweaked into a system of morality that got more complex.
Sorry to interrupt, but here I have to explain that moral is not what most people take it to be. In public meaning moral is a set of rules defining straight and clear what is good and what is bad just as the set of rules the mentioned communities had developed. Moral instead first defines a set of actions and then elaborates under which circumstances these actions are to be considered good or bad or anything between. I think that can be seen most clearly on the moral issue of killing a dictator. I'm proud to say that I'm completely immoral. I just and plainly believe that killing a human being is a bad thing and with the case of a dictator it's even worse because after killing him we don't have him around to show him off as a deterrent example. Besides, if killing him seems to be the only way to get rid of that person as a dictator it won't work anyway because the framework of this dictatorship will be still in place waiting for someone else to take over.
Sorry for the interruption but there are things that had to be said.
So now we have the two main components of religion (ideology and ritual).
A set of rules given by a divine being indicating a sole ruler to be appropriate to run a society followed by a bunch of secondary rules saying how to apply the primary ones to your live in a way so that it takes a secondary ruling class of priests to explain that to you.
If you now take the leisure time activities of the communes, song, music, dance and feasting (and of cause a lot more) and bind them into sacred rites then you have your religion.
And so it was done. Obviously it did not work.
So alternately the tribes kept on conquering and unfortunately they prevailed.
Of cause religion was kept as it helped to control population and proved a mighty tool to uphold a hierarchic society.