I assume that religion is subject to evolution just like everything else. If I am right, then there must have been a beginning for religion. I suspect it started with agriculture when people found that they had more free time. They didn't have to spend every waking moment hunting and gathering food anymore. With more time, people started to do more thinking.
And thinking led to more questions. What are the stars in the sky? Where is my dead son now? Why do I see my dead son when I sleep, but not when I am awake? When will I die? What happens when I die? How did I come to be? How did the world come to be? What went on before? What will happen in the future?
And I imagine that the wise man of the group had to answer all these questions. Does he answer with "I don't know"? That would never quiet the questions, so, what does he answer with? I suspect that he answered with things that seemed intelligent, but there was no way to prove him right or wrong.
And as the groups got bigger and people had specialized jobs, the wise man became wise men, and the wise men came up with something that gave them more power and control over the group. So that they would not contradict each other, they probably had to standardize their religion.
And after 5000 years, religion is still the way to control the masses.
Do I sound like one of those wise men? :o)