Religion is a byproduct of the evolution of our mind.
Religion is how the powerful few control the masses.
Religion started about as worshiping of animals, to multiple gods to the now all powerful god. And its is evolved it became more and more controlling and polarizing. Creating a us vs them situation. It is just another from of tribalism.
That seems right. We started thinking beyond everyday survival, and didn't have the answers, so we started projecting our dream minds into what we thought might be real.
I might add that man never could understand his dreams. While sleeping he is someplace else in a realm where he can do things he could never do here. I sleep and travel in the god realm.