The social norms practiced by religion were developed over millennia of cultural evolution—generations upon generations of trial and error, weeding out those social and cultural practices which did not benefit society and embracing those that did. The people of those societies along the way were not aware of this process. They did not know why certain norms worked and others did not. They had no scientific method to explain the causes and effects of what was happening around them.
Instead they had religion (myths, stories, and superstitions) which they used in an attempt to make sense of and understand society, its norms and practices. Religion was used as evidence for why things happened, and dogma became an incentive for society to practice those norms that seemed to lead to good outcomes. Religious leaders would tell the masses that this is the way you should behave and act if you want to avoid pain and suffering in this life and/or the afterlife.
Of course they didn't have any proof of such things, other than the fact that, generally, if you adhered to those social norms and cultural practices supported by the religion, more often than not your life and that of society as a whole would turn out better. That is if the religion was tried and true, having lasted for centuries. To withstand that long, they had to be doing something right.
That's the way society worked for thousands of years until the scientific revolution and the enlightenment. The scientific method started to give people some understanding of things they previously did not understand. They questioned the practices of old and began to test them and search for scientific evidence for given claims. This inevitably confronted the dogma of religion.
Through science, society came to understand that much of the social and cultural practices encouraged by religion had no scientific grounding nor did much of the claims and beliefs of religions themselves. Hence the scientific movement began to dismiss religions and build a secular society with new social norms and cultural practices in which much of the norms previously practiced by religion were dismissed—such as monogamy, heterosexuality, chastity before marriage, patriarchy where the male provides and the female cares for children and raises them with religious values. This secular movement resulted in embracing liberal values and giving more freedom to individuals. Much of what came from this movement was and is good, but it's fairly evident that also with this came much harm to society and individuals.
A new societal revolution in human understanding is due. It will not be a dismissal of science nor a reversion to religion. Instead, society will use science to understand how and why many social norms embraced by religion in the past worked so well to create a cohesive and stable society. We will test through trial and error which religious practices truly are worth keeping and which of the more secular liberal practices are worth keeping as well. Just as the scientific revolution shouldn't have thrown out the baby with the bathwater of religion, neither should the post-rational society throw out the baby with the bathwater of science and liberalism. The great challenge of our future society will be figuring out how to balance those opposing forces—liberal and conservative, science and religion—because embracing too much of one without the other can lead to the downfall of society.