The origins of religion will never be known as it began before recorded history.
I think a fair assumption is that it was an explanation by some of why how things happen that was beyond their understanding. Those who gave these explanations discovered that it gave them a certain amount of power over others who sought not just answers to how and why the world was as it was but advice on how to make it better or avoid it getting worse, thus religions began.
The formation of civilization required humans depart from natural instinct. According to science and evolution, humans had been migratory hunters and gatherers and then herders, for a long time; million years. To go from these instinctive ways, to living in a fixed artificial location; civilization, required something that could alter the inertia of natural instinct. Religion was part of a counter POV; frontal lobe, that offered a way to alter the inertia of instinct.
The story of Adam and Eve, in paradise, before the fall, was when humans were connected to natural instinct. Natural instinct allows all our choices to be optimized and made for us. What changed this; fall from paradise, was conscious knowledge of good and evil. This was a countering POV, that starts to inhibit the old ways of instinct. Morally neutral instinct, becomes polarized, and subject to choice.
Civilization had many startups before it finally stuck. There is evidence of very early civilization startups, thousands of years before Mesopotamia. However, all these early start ups, were aborted. This observation suggests that the first countering change in human nature, was not strong enough to overcome instinct. The brain continued to default back to natural instinct. The Tree of knowledge of good and evil; law, was there before Adam and Eve. It was not a problem early on. The first civilizations tried law, but were not successful; permanent.
The invention that coincides with the time scale of Genesis and the fall of Adam and Eve (from instinct); 6000 years, is the invention of writing. Spoken language came thousands of years before written language. Writing language coincides with the first stable civilizations. Once things were written down, the dynamics became different from the spoke traditions of law. This is when civilization stuck.
Word of mouth; spoken language and ideas, will change with time, as people recollect differently and/or embellish the story. Writing is different, in that even if we change the spoken story, a written copy brings us back to step one. The carved in stone approach, was strong enough to overcome the inertia of instinct, which will alter the spoke story.
Spoken traditions could form civilization, but as the story; knowledge, changed with time, an abortion would happen. The founders could begin the civilization, but as their offspring disagreed on the rules, procedures and laws, decline begins to happen. Written language changes the confusion of memory recollection. Written language led to a deeper repression, that could not heal; reverse, as had been the case of spoken law. Written law caused a repression, that animated the brain; spirits of polytheism.
Today in modern times, science has no clue what natural human behavior is. It condones relative morality and choice, since choice means money, though the selling of goods and services. Bad choice means big bucks. Human DNA is conservative, therefore the repression of instinct remains, relative to a natural DNA baseline. Religion is way to deal with this civilization based repression. It helps get close to natural instinct. This was the role from the beginning. Adam and Eve fall fro paradise; repression. However, God remains with them, to gradually help then come home; tree of life.