Stephen Asma in Aeon:
Sigmund Freud, who referred to himself as a ‘godless Jew’, saw religion as delusional, but helpfully so. He argued that we humans are naturally awful creatures – aggressive, narcissistic wolves. Left to our own devices, we would rape, pillage and burn our way through life. Thankfully, we have the civilising influence of religion to steer us toward charity, compassion and cooperation by a system of carrots and sticks, otherwise known as heaven and hell.
The French sociologist Émile Durkheim, on the other hand, argued in The Elementary Forms of the Religious Life (1912) that the heart of religion was not its belief system or even its moral code, but its ability to generate collective effervescence: intense, shared experiences that unify individuals into cooperative social groups. Religion, Durkheim argued, is a kind of social glue, a view confirmed by recent interdisciplinary research.
While Freud and Durkheim were right about the important functions of religion, its true value lies in its therapeutic power, particularly its power to manage our emotions.
More here.