Calls have resurfaced for Alan Turing to be posthumously pardoned recently. He was prosecuted in 1952 for consensual homosexual acts under section 11 of the Criminal Law Amendment Act 1885 which criminalised "gross indecency" between men – the very same law under which Oscar Wilde had been prosecuted at the end of the nineteenth century. This is an ongoing stain on our society – and something needs to be done about it; if not by parliament then the courts may have to step in.

A brilliant mathematician and logician who led a team of dedicated code breakers in Bletchley Park during the second world war, Turing developed a universal model of a computer and is considered to be a pioneer of artificial intelligence. Turing's team helped crack the Enigma machine and it is no overstatement to say that without them Britain may not have defeated the Nazis. Not only were they unsung war heroes at the time, but shortly after the war Turing was subjected to appalling treatment by the very country he had helped save.

In order to avoid a prison sentence, Turing was forced to agree to chemical castration whereby he was injected with synthetic female hormones, which resulted in impotence and gynecomastia. In a final McCarthy-ist gesture, the conviction also led to the revocation of his security clearance. Less than two years after he began the horrific hormone treatment, he committed suicide, aged 41, by eating an apple laced with cyanide.

We hope the recent request for his pardon, spearheaded by Stephen Hawking, will be successful, but Turing's champions have been rebuffed before. In 2009 an e-petition calling for an apology attracted thousands of signatures. Gordon Brown, prime minister at the time, said he was "deeply sorry ... for the appalling way he was treated". But his conviction remained. A second e-petition called for a pardon and garnered tens of thousands of signatures. But in February Lord McNally, minister of state for justice, declined to pardon him because he was "properly convicted of what at the time was a criminal offence" and a private members' bill introduced by Lord Sharkey to pardon him has hit the buffers.

What could now make all the difference is a shift in the legal position. Posthumous pardons have been granted in a variety of cases: in 1998 Derek Bentley was pardoned; shell-shocked soldiers convicted of desertion in the Great War were pardoned en masse in 2006; and earlier this year the Irish Republic pardoned deserters from WWII.

But pardons are bestowed or withheld in what was thought to be the exercise of the ultimate form of executive discretion – the royal prerogative – and traditionally the courts have been reluctant to intervene in such decisions. Nevertheless, even this discretion has to be exercised in a rational way, taking proper account of relevant factors, including the way materially similar cases are being dealt with.

Were Turing alive, the petitions would receive a very different response. Under the Protection of Freedoms Act 2012, a person convicted under anti-homosexual laws (including section 11 of the 1885 Act) may apply to the secretary of state for such a conviction to be "disregarded" (providing the conduct in question would not now be a criminal offence).

A disregarded conviction has the effect that a person "is to be treated for all purposes in law as if the person has not been convicted of the offence". But section 92 applies only to living persons. The government's intention when passing section 92 was to recognise the injustice of the repressive old laws — even though they were validly passed at the time. So, on any view, McNally's moral justification for refusing to pardon Turing no longer holds water.

And it is also legally unsound too – section 96 of the 2012 Act expressly provides that the secretary of state's power to grant pardons is not restricted by section 92. It is perverse for the minister to refuse to pardon Turing for reasons which are diametrically opposed to the law which currently applies to living persons. The point is even stronger because the minister must exercise his discretion compatibly with the European Convention on Human Rights, which had been signed by the UK even before Turing was convicted, and which does not permit criminal convictions for consensual homosexual acts between adults.

Turing famously said "we can only see a short distance ahead, but we can see plenty there that needs to be done". Perhaps Hawking's plea will help the government overcome its blindness towards the unremedied injustice of Turing's stigma. If not, the courts may need to help it see.

Alex Bailin QC is a barrister at Matrix Chambers and was previously a mathematician; John Halford is a partner at Bindmans LLP. Both specialise in human rights law