For most of human history – and for rather a lot of the world today – blasphemy is the cardinal case of saying the unsayable. What could be more transgressive than mocking or abusing the all-powerful creator of the universe? But what is interesting in the history of religions is that this isn’t always about attacking or rejecting faith itself.

One regular and significant theme in legends, religious texts and historical anecdotes is that “blasphemous” language, ­language attacking, condemning or mocking God, can be forced out of people who are so ravaged and humiliated by their ­suffering that they turn on God in fury. Ajax in classical myth, Job in biblical narrative – these are figures who say, in effect, “I haven’t deserved this and I didn’t expect this. What claim can God have to be called good or just? And if my sufferings are ­supposed to remind me that life is mysterious and God is stronger than I am and so I ought to submit humbly, I can always refuse to accept these terms. I won’t be threatened into silence. How much worse can it get, anyway? At least I can die with my self-respect intact.”

This is a fierce protest against religion, but it can also be a step towards the affirmation of belief at a new level. Job does submit in silence at the enigmatic ending of the book; but only after God has said that Job has “spoken well” of Him. Job’s brutal challenging of God’s wisdom and benevolence has been part of the process of testing the limits of what a religious tradition can make sense of. The Anglican poet and novelist Charles Williams put it succinctly in saying that God demands from us that we demand explanations from him. And the language of accusing God, holding God to account, reproaching God with neglect or abuse, has long been part of the repertoire of Jewish and Christian usage. Frank Cottrell Boyce’s play God on Trial dramatised this tradition very powerfully, retelling the – possibly apocryphal but still haunting – story from Auschwitz of the group of Jews who tried God in a rabbinical court and found Him guilty of murderous neglect and breach of promise. The play ends with all of them ­filing into the gas chambers, covering their heads for prayer.

All this represents a complex mixture of emotions and convictions. If God is real, then presumably God can cope with anything we choose to throw at Him. If God is not real, the experience of rejecting what we think we know of God is a way of discovering whether the notion of God actually matters to us. If, worst of all, God is incompetent, sadistic or indifferent, the language of protest at least allows us to die with some integrity and dignity; we have – as Ajax and Job have obviously concluded – nothing to lose.

If God is real, these “thought experiments” are all to do with testing what we really believe. The violent rejection of a God who has failed to save or protect may open up a new picture of a God who isn’t there to save or protect but just is what He is, the silent centre of a moral world: the tormented French philosopher Simone Weil argued that any picture of God that survived genocide would be almost unrecognisably different from any earlier one. “Blaspheming” against the God who fails – attacking your own religious comfort zone – can be a moment of maturing faith.

Or not, of course. Blasphemy of this kind is risky because there may indeed turn out to be nothing left on the far side. You test the limits of your faith and discover that when you have rejected the God of infantile satisfactions and securities, what remains is not the transformed and elusive God of a ­Simone Weil, but just nothing. Which is why religious institutions don’t exactly encourage these transgressive experiments, why they are so often suppressed with passionate severity and violence.

But this is where we come up against the main catch-22 of the whole thing. If you are forbidden to voice the hard questions, this might suggest that faith survives only by never being challenged. The person who actually expresses their fury or disgust or disillusion can, at least sometimes, be ­demonstrating faith of a sort, confidence that, if God is real, it is possible, even necessary, to say what you feel about Him – and that, unless you can say this, the God you started with is not worth believing in. This underpins many of the Jewish Psalms or the poems of George Herbert or Gerard Manley Hopkins. Blasphemy resists the conspiracy of silence about the agonising difficulties of belief, resists the stifling of a real and honest response to an unjust world.

It is in the light of all this that, for many religious people, legislating against blasphemy is a deeply ironic thing. The project of punishing blasphemy with the fullest rigour of the law can imply a God anxious about His safety, whose power is uncomfortably like any arbitrary human power – insecure and needing to be held in place by violence. Legislating against blasphemy is always in danger of suggesting that God needs human protection and that faith is so frail that it cannot survive exposure to honest human emotion or intelligence.

In practice, such legislation has a deeply unimpressive history. Blasphemy laws can be and have been used to ruin reputations, to settle private scores, to reinforce a regime’s unchallengeable authority. The ongoing issues with blasphemy legislation in a country such as Pakistan are not only about freedom of speech but about the blackmail and intimidation and official collusion with mob hysteria that have repeatedly cost the lives of members of religious minorities, especially Christians. They also represent a menace for Muslims themselves, vulnerable to the irrational and unaccountable workings of this legislation.

It often looks as though Muslims have more of a problem than some other religious groups about blasphemy. But this is a slightly misleading judgement. Apart from the fact that Christians past and present have sometimes been as sensitive as any Muslim, we need to keep two things in mind. One is that the whole of Islam is based on a fiercely consistent refusal of idolatry – confusing God with things in the world. If a narrative or a picture is thought to be doing this, it will arouse maximal resistance, even from those who turn in disgust from violence and bloodshed. It strikes at something central. The other is that, while Judaism and Christianity often talk about God in terms of paradox and irony, Islam would regard this as a self-indulgence: the language of the Quran is believed to come directly from God, so that the idea of a God who speaks through irony or indirection seems to Muslims like an evasion of plain truth or the rejection of a generous and straightforward gift.

And it should be clear that the ­blasphemy we have been discussing is something a bit different from the casually irreverent phrase, the mocking caricature of belief, the “offensive” image or narrative such as Scorsese’s Last Temptation, or Jerry Springer: the Opera, or even Life of Brian. These are “transgressive” only in a rather thin sense. For most contemporary western commentators, these things offend people who are not “us” – not privileged and semi-detached heirs of the Judaeo-Christian tradition. They don’t touch real issues of conflict, power or change within the “modern” belief system. Most of us find it hard to imagine that religious language and imagery could matter in such a way that it would be ­urgent and imperative either to protest or to suppress the protest. When we encounter those for whom it matters intensely and who have no scruple in defending their God with the utmost violence (as in the Charlie Hebdo killings or the more recent ­murders in Bangladesh), we are repelled and bewildered.

So there is something of a paradox here, too. If we want to understand why casual blasphemy causes such homicidal frenzy, we badly need to understand and imagine better why and how faith matters. But one of the things that tells us most about this, from the imaginative point of view, is the way the blasphemy of angry protest, bitter satire and disillusioned rejection works within religious traditions. Herbert, Job and some of the Psalms remind us that sometimes the seriousness of faith is most effectively explored precisely in the risky business of testing the limits. And without such testing, such forcefully expressed doubt, you may never know the real strength or weakness of what you claim to believe. The secularist needs to understand some of the internal critique that faith is always struggling with; and the believer needs to recognise that blasphemy isn’t necessarily a matter for panic, let alone violence. It may even be a gateway into a larger and more durable commitment.