I fail to see how you get religion out of thin air
You don't. As with literally every social construct, someone needs to say it to multiple people - and then those people need to accept it.
You don't even need everyone to accept it.
Anyone that accepts it is part of the social construct - and if that social construct helps the species survival - then the people who didn't accept will, to some form, accept it if they want to benefits of the social construct.
If you don't want to be part of it, that's fine. You can live like every other animal on this planet does, but that can be a brutal way to live compared to the comforts our constructs provide us.
Literally nothing happens out of thin air when it comes to our social constructs. We make them. That's why our species went from middle of the food chain to the top.
Is your issue with religion the problem with the spiritual or religious portion of it? Because that is completely irrelevant. If you can agree a law is real (it's not physically real, it only is real in our minds) then you, by extension, have to agree religion as a means to govern human behavior is real as well.
Neither of them are physically real - you, nor any living being, can touch a law, a right or a religion. They are myths homo sapiens came up with to govern behavior and ensure our species' survival.
Back when our biggest concern was getting our next meal and running from being eaten alive, someone at some point realized, "Hey! If that other group of homo sapiens over there helps our group we can kill these bigger animals, have more food and more protection!"
And thus, the social construct was born. It was a way to convince a group of unknown homo sapiens to work with your group and other groups, together, because we were probably being eaten alive everyday at that point. The people who accepted the social construct had a better chance of survival, and evolution takes care of the rest.
Who knows what early social constructs were like, they were probably full of whatever crazy ideas we could think of because we had no clue how anything worked. So a mystical God was pretty easy for everyone to believe at the time
Look at Indian tribes and their beliefs, as an example.
Also, don't forget, we weren't always the only species of the genus homo around. So there was fighting between different species of the homo genus as well - and inbreeding too. 3 to 4 percent of homo sapiens DNA in the Asia region is still Neanderthal DNA.