Religion is some concept of a supreme being, rituals and philosophies grouped into one. God is a substitute to a leader. God show us the path we should follow and reward people who follow it and punishes those who don't.
Everything was a mystery to our ancestors. They feared thunder, earthquakes, volcanoes etc. They wondered about death and what happened afterwards. Their origin was a big mystery to them. They tried to find answers for things happening to them or things happening around them. In some cases they found the answer and in other cases they imagined the answer. As for the origin there is god and stories of origin. For death there are rituals, the concept of spirits, spirituality, afterlife, rebirth, hell, heaven etc. For thunder, volcanoes or other such things they feared, there are rituals, prayers, legends, myths etc. Then there was the search for how to live a good life, and people were also curious about the purpose to our lives. A lot of purposes were proposed. The ones that went well with the earlier concepts of god, spirituality, origin stories etc got more acceptance. Proposed purposes that could modify the existing beliefs to suit it could also get accepted. Then people asked why other life forms isn’t having rituals or prayers. Some of them believed that it is because we are better than them. They believed that since we are more intelligent and have a sense of morality, only we can understand god and his intentions. A grouping of such concepts is essentially what a religion is.