I think that, in general, we need to have an explanation for the fact that we are here, that galaxies, suns and planets exist in never-ending space, as the vastness of the universe is difficult to comprehend.
If we cannot comprehend this we need to rationalise it in some way and that is how gods and religions emerged, to fill in the gaps.
As increasingly more knowledge is discovered and gaps are filled, fewer people will believe in higher beings to explain why and how we are here.
Religion was also a way to control people and, generally, people are better educated and less compliable now.
I'm just musing and hope you can follow my not-very-bright thoughts.