Look, I'm going to lay this out as straight forward as possible because I know people are dumb as fuck and they like to have everything handed to them.
Religion was created out of FEAR.
Fear. As an "intelligent" animal (I use that loosly), humans feel the need to explain what they do not understand. Take the ancient Greek and Roman gods. Why were they created? It was for the sole cause of explaining the natural disasters that were happening around them. Lightning, flooding, tornadoes, etc. were thought to be a god's way of punishing them for doing something wrong. That's why they created statues and monuments- to praise a specific god as ask for the god not to bring plagues and burden down upon them.
Now, as science has evolved, in this modern day, we can explain why lightning, flooding, and tornadoes occur. Therefore, we look back at the Greek and Roman gods in jest because it seems so silly to think a god was responsible for this. AS SCIENCE EVOLVES, RELIGION BECOMES OBSOLETE. But the Roman and Greeks are not as outdated as we think. Instead of making a god for lightning, it's a god for death. Instead of statues to worship, we have churches.
Nowadays, we STILL have gods to explain what we can't- "why are we here?" and "where did we come from?". We, as humans, have the capacity to think above normal survival tactics, unlike other animals. It's natural that we would want to think that we are somehow super important, that WE are the center of the universe. JUST BECAUSE SCIENCE CANNOT EXPLAIN SOMETHING, THAT DOES NOT MEAN THAT WE HAVE TO CREATE A GOD FOR IT. It is completely okay to say "I don't know". How did we get here? I don't know. What happens after we die? I don't know and I'm okay with saying that. It's FEAR that makes people create gods. We fear death. We fear what happens after death. To ease this fear, we create a fictional place that you will go to be with the other people you love. Think about it. People were so afraid of death that they HAD to create a place that they could go AFTER death to LIVE, eternally...no death in eternity.
If science could provide an answer to "why we're here" or "where did the earth come from" then religion would become unnecessary.
In today's society, we can control our bastard children by drugging them up. Unfortunately, back in time, there were no ADD pills to keep their little shits in line. What is scarier than an almighty father figure ready to sent your punk ass to hell when you step out of line? Not to mention that you'd be stoned first...by your family no less. But remember, God loves you! <3