Religion is an extension of our natural survival mechanism.
Human brains, specifically the left hemisphere of the human brain, have an innate need to explain and rationalize everything it sees. This powerful drive to seek explanations is probably what I believe led to the formation of religion.
The Divinity of the Unknown
The ancient human was confused. They did not know why thunder occurred, or why the sun disappeared during the eclipse, or why fire burned. This made them feel lost and out of control.
But if they (early humans) could believe that these were caused by a divine entity, a God, it gave it an explanation, a rational excuse to understand the incomprehensible. Once humans learnt how to rationalize events with irrational stories, they gained control over the narrative of “reality”.
The Fallacy of Control
But with control, comes the false sense of influence. If a God-like entity exists, then surely one can try to curry their favor, right?
Hence, people started praying and offering sacrifices to their respective deities, all to feel like they, mere humans, had the power to influence unbelievable natural phenomena.
Influence begets control, and control needs a hierarchy to sustain it. The rise of religion led to the rise of community.
Communities operate within the constraints of the laws that govern it, and religion became the proponent for enforcing these rules. Religion propagated a set of social norms (mostly inspired by common sense and morality) by offering the threat of punishment (hell/purgatory/bad karma) and the promise of reward (heaven/good karma).
Was this a bad thing? Nope. In fact, most of these rules were actually good. Religious teachings then (and today) forbade many criminal activities — no killing, no adultery, just rules to be a nice little human.
So Where did Religion go Wrong?
Probably, very soon after its inception.
Humans by nature, are self-centered creatures. We see patterns in things, and compare it to ourselves. We see shadows and assume it to be monsters, or have strange dreams that we assume have a hidden meaning because as an individual, we are “special”.
We love grand, entertaining stories, and when we are told things, we end up mishearing and cooking up parts of our own (think: Chinese Whisper).
Religious lore and stories are told over the course of many years, often millennia. With each generational narration, these stories change — they get wilder and more supernatural, and mostly lose their original meaning.
The stories which were once optimized to deliver moral lessons, are now optimized for entertainment.
Another religious fallacy is when we learn things from the adults around us. Scientific temperament is not an inherent human characteristic. As children under the care of parents, we are taught things, and we take them as facts.
When a child asks something complex, and the adult is too busy to explain it to them, they will make up a supernatural explanation for it. Someone’s dad didn’t have the time to explain lightning?
They might have said: "Yes son, lightning and thunder happens when the lightning god gets angry at you for being a bad kid."
This indoctrination of the youth cements the craziest ideas into the kid's heads, and sometimes, even proving them wrong will mostly not sway their opinion.
Society and Control
Now we look at groups and society. Religion provides people a higher authority to serve; it gives a method of control, and laws created for the betterment of one group turns into the word of God.
This is probably what happened with cows in India.
Cows, apart from being delish hamburgers, were also a source of milk.
Maybe the dairy farmers were in a better societal position than butchers, and they enforced a no-killing rule, which slowly evolved into the Word of God.
A Short Conclusion (And Why I Identify as Non-Religious, but not Atheist)
I believe that God and Religion are two very different concepts.
God refers to a supreme creator (could be an intelligent entity, a sophisticated algorithm, or even a cosmic game of chance) whose existence can neither be confirmed nor denied. The concept of God might be man-made, but God is not a human creation.
Religion on the other hand, is a survival mechanism gone wrong. Religion holds a lot of influence over a lot of people — it is a power that keeps people in line.
But unfortunately, power corrupts.
When your religion says women are nothing but men's property and that kids can be sold as brides, it is very clear that religion is less the Word of God and more the twisted will of corrupt men.