Religion was one of the stronger organizing forces of the old world and so good and bad both have roots in it. It was more stable than the leadership of kings/queens/chieftans which was blood-run and disrupted by the murder of either the existing leadership or the entire bloodline. Chaotic at best.
Learning/education has been shown to be part of religious teachings long before JC was even a discussed historical figure. For example, Buddha taught under Bodhi trees, Hindu philosophers under Banyans and so on. All kinds of 'modern' conceptions came from religious individuals, because most everyone was religious. It was deeply intertwined with early culture and simply belonging to a given geo-community
Our rejection - and I do mean our - of religion and easier coexistence culturally as atheists and agnostics is relatively recent.
But, no, in general people in the past believed their own religions. We are atheists culture and large atheist traditions at this point, we have hard time imagine it.
That's what organized religions did/do to non-believers. They burned them at the stake. Or stoned them to death, Or drowned them, or exiled them.
If your goal is to make contributions to society, in that context you're damn well going to say whatever you need to say about your personal beliefs to ensure that kind of shit doesn't happen to you. Hell, even if you don't care about making contributions to society you're still gonna say what ever needs to be said to ensure you don't end up burned at the stake.
The end result of all these theistic threats is that a lot of people who made great contributions to society did so under the auspices of religious organizations not because they genuinely believed in the tenants of those organizations, but because they had to.
And those organizations made those threats, and continue to make those threats because they know that this is the outcome -- that people will do things in their name to avoid the shit that the religion can do to them.
It's a racket, much akin to the mob coming up to a shop keep and telling them that it would be a shame if something were to happen to their business if it didn't have some kind of 'protection' that the mob can offer them.
It's no coincidence that the Catholic church and the mob originate from the same part of the world.