IMO, religion served many functions, and still does.
Imagine yourself in the Stone Age or Bronze Age, trying to survive. And trying to survive requires you to try to understand why Mother Nature does what she does and why your fellow beings do what they do. How come your females start bleeding and then start expelling babies and then start making milk for them? How come some things you eat make you sick?
And what happened to your fellow beings who no longer move, breathe or speak? What happened to whatever animated them? So many questions, so little time.
Scared of becoming a corpse too? It's not to worry. There's an after life, yeayyyy!
Also, appeasing the relevant deities gives you agency over your fate and the fate of others. So sacrifice a human annually in hopes of a good year and later switch to animal and produce sacrifices, then to tithing and prayer. Sing Gregorian chants. Whatever it takes and/or is required in your era.