For Alexis de Tocqueville, religion is important for liberty as an extension of society. What keeps a government in check, particularly a democratically elected government that can plausibly claim to represent the "people," is the existence of a distinct social sphere. Religion protects the social sphere by granting a moral authority that the government lacks. The opposite is also true that government needs to keep religion hemmed in within the social sphere so that it evolves to focus on the non-physical and that clergymen learn to value the respect they gain precisely by not being tainted by politics more than the power they could gain through politics. From this perspective, religion and politics, while maintaining their separate spheres can have a positive influence on each other. Religion keeps government away from society and the government keeps religion out of politics. Hence government and religion render each other suitable for liberty.
Removing religion from the equation would start an avalanche that would eliminate reason and ultimately liberty. According to Tocqueville:
When religion is destroyed among a people, doubt takes hold of the highest portions of the intellect and half paralyzes all the others. Each person gets accustomed to having only confused and changing notions about the matters that most interest his fellows and himself. You defend your opinions badly or you abandon them, and, since you despair of being able, by yourself, to solve the greatest problems that human destiny presents, you are reduced like a coward to not thinking about them.
What I find fascinating about this passage is how well Tocqueville diagnosed the post-modern condition. Following Kant's famous dictum of sapere aude (dare to know), we tend to think of reason as something done by individuals without any reference to tradition. In truth, even as individuals are the only meaningful moral unit, reason is fundamentally a social activity that works across generations through the process of tradition.
The reason for this should be obvious to anyone familiar with the free-market tradition. Individuals by themselves are not capable of doing much beyond eking out a mere hunter-gatherer subsistence existence. Economic production and ultimately civilization is only possible through large-scale cooperation. If individuals are so lacking in economic wisdom, how much more so must it be when it comes to the higher truths of the world such as morality and the meaning of life.
Just as we cannot expect people to literally reinvent the wheel or the lightbulb (contrary to Ayn Rand's hero in Anthem), we should not expect people to construct their own philosophies from scratch without reference to tradition. For example, I can accept that Euclidean geometry is TRUE even as my understanding of mathematics is rather rudimentary. Whether or not Euclid or other mathematical claims can be considered objective facts at the end of the day, the critical issue is whether they have greater authority than my personal "lived experience" of oppression. I live my life under the assumption that there are things outside of me that are objectively TRUE and, unlike divine revelation, knowable to human beings regardless of their time, place, race, or religion.
It is a fair question as to whether or not the truths of reason, such as mathematics, can offer transcendent meaning. My suspicion is that any attempt to do so is going to eventually start to look a lot like a religion. (One thinks of the example of the Pythagoreans.) What happens to someone stripped of transcendent meaning transmitted through society and ultimately tradition? They will have to retreat into their own heads, a place too small for either faith or reason.
This has implications for democratic government. Democracy is not a license for people to do whatever they want. On the contrary, democracy requires great personal discipline. This is possible if there exists an independent society outside of politics and backed by religion to train people to stand on their own feet. The moment a person starts to ask "who will feed me" they are already are slaves in their hearts even before any master shows up and one certainly will.
What happens when people lose their religion? Tocqueville anticipates Hannah Arendt in predicting that an atomized nihilistic society would be ripe for totalitarianism.
Such a state cannot fail to enervate souls; it slackens the motivating forces of will and prepares citizens for servitude. Then not only does it happen that the latter allow their liberty to be taken, but they often give it up.
When authority no longer exists in religious matters, any more than in political matters, men are soon frightened by the sight of this limitless independence. This perpetual agitation and this continual mutation of all things disturbs and exhausts them. Since everything shifts in the intellectual world, they at least want everything to be firm and stable in the material order, and, no longer able to recapture their ancient beliefs, they give themselves a master.
For me, I doubt that man can ever bear complete religious independence and full political liberty at the same time; and I am led to think that, if he does not have faith, he must serve, and, if he is free, he must believe.
Just as reason requires a sense of being part of a larger tradition such as a religion, so does liberty. A person without religion who retreats into their own head without any sense that there are larger truths beyond his personal feelings will also not be able to justify standing up for liberty. If man cannot engage in higher truths such as reason, what does he need liberty for? If the truths of mathematics cannot stand against one's personal feelings then it will also fail to stand against the physical reality of the dictator in power.