There was originally no common-law offence of blasphemy: blasphemy was an ecclesiastical offence which was dealt with in the church courts. The first criminal prosecution was R v Taylor (1676) 1 Vent 293, in which Lord Hale CJ said that blasphemy was a crime against the laws, state, and government, because "to say, religion is a cheat, is to dissolve all those obligations whereby the civil societies are preserved". He also said: "Christianity is parcel of the laws of England; and therefore to reproach the Christian religion, is to speak in subversion of the law".
In a much later blasphemous libel case, Whitehouse v Lemon  AC 617 (the well-known Gay News case), Lord Diplock had this to say:
In the post-Restoration politics of 17th and 18th century England, Church and State were thought to stand or fall together. To cast doubt on the doctrines of the established church or to deny the truth of the Christian faith upon which it was founded was to attack the fabric of society itself; so blasphemous and seditious libel were criminal offences that went hand in hand.This was presumably why one individual was prosecuted for seditious libel when he published a book against the teachings of the Church of England (R v Keach (1665) 6 St Tr 701). Nor did the Libel Act 1792 make any distinction between seditious and blasphemous libel.
Blasphemy was put on a partially statutory basis by the Blasphemy Act 1697. This explicitly prohibited people who had been brought up as Christians from denying the truth of Christianity. Its purpose seems to have been simply to add new penalties to the common law of blasphemy. This Act too had a political as much as a religious purpose:
[M]any persons have of late years openly avowed and published many blasphemous and impious opinions, contrary to the doctrines and principles of the Christian religion greatly tending to the dishonour of Almighty God and may prove [sic] destructive to the peace and welfare of this kingdom....The link between blasphemy and civil order was affirmed from the opposite perspective by Lord Raymond in R v Woolston (1728) 2 Stra. 834. He said: "To say, an attempt to subvert the established religion is not punishable by those laws upon which it is established, is an absurdity." This argument is that blasphemy is wrong because it offends against the established religion, which is a creature of the civil law, not because the effectiveness of the civil law depends on punishing blasphemy.
In his celebrated Commentaries, Sir William Blackstone endorsed the idea that blasphemy was prosecuted in the criminal courts for the sake of society and not for the salvation of souls:
I proceed now to consider some gross impieties and general immoralities, which are taken notice of and punished by our municipal law; frequently in concurrence with the ecclesiastical, to which the censure of many of them does also of right appertain; though with a view somewhat different: the spiritual court punishing all sinful enormities for the sake of reforming the private sinner, pro salute animae; while the temporal courts resent the public affront to religion and morality, on which all government must depend for support, and correct more for the sake of example than private amendment.The same thinking was at work in the wave of prosecutions brought against publishers of Thomas Paine's The Age of Reason. The concern seems to have been that the book was a revolutionary text and dangerous to the state:
The fourth species of offences therefore, more immediately against God and religion, is that of blasphemy against the Almighty, by denying his being or providence; or by contumelious reproaches of our Saviour Christ. Whither also may be referred all profane scoffing at the holy scripture, or exposing it to contempt and ridicule. These are offences punishable at common law by fine and imprisonment, or other infamous corporal punishment: christianity is part of the laws of England. (4 Bl Com (14th ed.) 58-59)
Indeed, all offences of this kind are not only offences to God, but crimes against the law of the land, and are punishable as such, inasmuch as they tend to destroy those obligations whereby civil society is bound together; and it is upon this ground that the Christian religion constitutes part of the law of England; but that law, without the means of enforcing its precepts, would be but a dead letter. (R v Williams (1797) 26 St Tr 654, per Ashhurst J)Some years later, Baron Alderson confirmed that blasphemy against Anglican Christianity was illegal not because that faith was true, but because it was established by law:
A person may, without being liable to prosecution for it, attack Judaism, or Mahomedanism, or even any sect of the Christian Religion (save the established religion of the country); and the only reason why the latter is in a different situation from the others is, because it is the form established by law, and is therefore a part of the constitution of the country. In like manner, and for the same reason, any general attack on Christianity is the subject of criminal prosecution, because Christianity is the established religion of the country. (R v Gathercole (1838) 2 Lewin 237)It was at this point that the definition of blasphemy began to change. In 1841, the Commissioners on Criminal Law affirmed that "all denial of the Christian religion" was unlawful, albeit in practice "the course has been to withhold the application of the penal law unless insulting language is used". Yet the case of R v Hetherington (1841) 4 St Tr NS 563 established that merely denying the tenets of the national religion in a sober and temperate manner was not blasphemous. This principle was later endorsed in the case of R v Ramsay and Foote (1883) 15 Cox CC 231. In that case, Lord Coleridge CJ noted that "protection for the constituted religion of the country may be a good thing even for those who differ from it" - again, it mattered less whether Anglican Christian was true than whether it was useful.
There were very few blasphemy prosecutions after R v Ramsay and Foote - it is said that only five took place between 1883 and 1922. In this period, however, there fell one of the principal secularising cases of the modern era, Bowman v Secular Society Ltd  AC 406. In this case, which I have blogged about elsewhere, the Law Lords indicated that the origin of blasphemy as an offence lay in legal and social considerations rather than considerations of piety or theology:
[T]he gist of the offence of blasphemy is a supposed tendency in fact to shake the fabric of society generally.... (Lord Sumner)
[T]he fact that Christianity is recognized by the law as the basis to a great extent of our civil polity is quite sufficient reason for holding that the law will not help endeavours to undermine it. (Lord Finlay)There were no prosecutions for blasphemy between the 1922 case of R v Gott and the Lemon case in 1978. When Lemon reached the House of Lords, Lord Scarman took the opportunity to note:
The offence belongs to a group of criminal offences designed to safeguard the internal tranquillity of the kingdom.Thereafter, blasphemy entered the history books, aside from a quixotic attempt to mount a blasphemy prosecution against Salman Rushdie's The Satanic Verses (R v Chief Metropolitan Stipendiary Magistrate ex parte Choudhury  3 WLR 986). The offence was finally abolished by the Criminal Justice and Immigration Act 2008, s.79. The first attempts at abolition had come as long ago as the 1880s.