Religions are ubiquitous to humanity, and have probably existed for as long as humans have had any kind of rational higher-level thoughts. It's often hypothesized, from a purely secular point of view, why did religions form in the first place, and why they are so ubiquitous. Some hypothesize that, from an evolutionary perspective, religions offer a survival advantage to the species, which is why they are so prevalent. Others hypothesize that religion is simply a side-effect, a by-product of something else that was evolutionarily advantageous. (Such side-effects are extremely common in evolution, after all.)
Personally I find the latter idea more plausible. I'm not an evolutionary biologist nor an anthropologist, but I can perfectly well imagine that the origin of religions is something like this:
Humans are a social species, and have been so for a really long time, even from before our ancestors could even be classified as humans (ie. homo sapiens.) In our case being highly social was a survival advantage because we weren't so fit for survival as individuals. Strength in numbers, and so on.
For a society to work, some ground rules must be agreed upon, and all the members of that society have to agree to follow those rules, for the benefit of everybody. This is, in fact, where "morals" come from (especially the instinctive ones.) Those individuals who obeyed the norms of society had a bigger survival advantage than those who didn't, and therefore an instinct to follow societal rules was naturally selected.
Societies themselves evolved into being quite authoritarian. After all, what good are societal rules if the members of the society don't follow them? If there's someone who breaks the rules and harms others by doing so, the others are prompted to do something about it. To enforce the rules. The law breaker is punished or cast out of the society. This further strengthens the natural selection happening that prefers individuals who obey the rules of the society.
It was thus only natural for an instinctive "respect the authority, the authority knows what's good for me and everybody around me, abhor people who don't respect the authority" mentality to form. The stronger that this instinct was, the higher the survival advantage.
While "authority" in this case could well be a concrete person or persons, more generally it was much more abstract. Originally, "authority" was in fact the society itself. The instinct was to follow the society, regardless of who was concretely in charge. And this society, the "authority", was conceptually larger and more powerful than any single individual.
Is it any wonder that at some point this went a bit overboard? People started instinctively respecting a "higher authority" that was much larger and more powerful than themselves, and from which everything that's good and beneficial came from. The source of all morality and rules. As the mental capacity of humans increased over time, it was only natural for these people to come up with all kinds of invented descriptions and claims about this "higher authority."
The abstract concept of "the higher authority" (which was originally just the society as a whole) became more and more concrete, albeit fictional, as the stories developed and were repeated. Every storyteller would add their own flavor, their own details. Their listeners would repeat these stories to their children and other family, and so on.
In other words, religions are simply a by-product of humans being a highly social species (which has a survival advantage of obeying the rules of the society.)