A reading group in the library of Wandsworth prison, south London. Photograph: Martin Godwin for the Guardian

The blanket ban on sending books to prisoners in England and Wales has been declared unlawful by the high court.

Mr Justice Collins has quashed the ban imposed by the justice secretary, Chris Grayling, and ordered him to amend his policy on what can be sent to prisoners.

In his ruling, the judge said that it was strange to treat books as a privilege when they could be essential to a prisoner’s rehabilitation.

“A book may not only be one which a prisoner may want to read but may be very useful or indeed necessary as part of a rehabilitation process,” he said.

The judge also criticised Grayling’s open letter responding to a protest by the poet laureate, Carol Ann Duffy, with the “somewhat misleading” impression that prisoners could order unlimited books from Amazon via the prison shop.

The case was brought on behalf of HMP Send prisoner Barbara Gordon-Jones, a 56-year-old convicted of arson, who has a doctorate in English literature. The judge acknowledged that the books she wanted to read were not those normally required by prisoners. The court was told that when she saw a neurologist in March she was reading Alan Bennett, Monica Ali and the dialogues of Marcus Aurelius.

“This is a wise, just and irrefutably correct ruling,” said Duffy. “We all look forward to hearing to which prison library Mr Grayling will be sending books for Christmas.”

Philip Pullman was also delighted: “Clearly the Ministry of Justice was taken aback by the public reaction to their mean and vindictive ban, and tried to claim that there was nothing new, it only enforced an already existing rule, and so forth. Bluster. I’m very glad that the courts have seen through it, and stated that reading is a right and not a privilege,” he said.

Denis MacShane, the former Labour MP who was jailed for expenses offences, said: “library.All envelopes and packets are opened and searched when they arrive in prison and the idea that drugs or extremist material arrives in the post is just nonsense.”

The Howard League argued that the policy on relatives sending in essentials to prisoners should be restored to the previous position leaving it to the governors’ discretion as to how many or what type of parcels prisoners could receive.

The judge says he accepts that there was no intention by ministers to prevent prisoners getting access to books. The existence of prison libraries and the provision to order books with their weekly prison earnings, which can be as low as £2.50 a week, meant the restrictions stopped short of an outright ban on books in prisons. But he says the inclusion of books in the restrictions on what can be sent in by family and friends under a new incentives and earned privileges scheme was seen as a ban on books.

Collins said in his judgment: “I see no good reason, in the light of the importance of books for prisoners, to restrict beyond what is required by volumetric control … and reasonable measures relating to frequency of parcels and security considerations.”

A Prison Service spokesperson said: “This is a surprising judgment. There never was a specific ban on books, and the restrictions on parcels have been in existence across most of the prison estate for many years and for very good reason.

“ Prisoners have access to the same public library service as the rest of us, and can buy books through the prison shop.

“ We are considering how best to fulfil the ruling of the court. However, we are clear that we will not do anything that would create a new conduit for smuggling drugs and extremist materials into our prisons.”

Frances Crook of the Howard League said: “We are very glad that common sense has now prevailed in time for Christmas, when for three weeks prisons will be virtually in lockdown. During that time, receiving a book from a loved one could literally save a life.

“We now call on the Ministry of Justice to relax the ban on sending in parcels completely so that prisoners can receive essentials such as underwear and small gifts from their children. This would help to alleviate distress in prisons at a time when they are in crisis.”

John Healy, whose 1988 memoir The Grass Arena chronicled his journey from a life of street drinking and petty crime to a chess Grand Master, said the ban on books being sent to those serving sentences was a counter-productive measure, and welcomed the ruling overturning the policy.

He said: “It is great news – but it should never have been suggested in the first place.

“It is obvious that books can play a key part in a prisoners rehabilition – they did for me. They were a catalyst. Books helped me come to terms with how I had lived my life.

“It is very hard to be both a reader and a villain. Reading helps you understand the world around you and relate to how your behaviour effects others. It should be encouraged as much as possible.”

He added the book ban made it clear the Conservative minister did not place prisoner reform at the heart of justice policy making.

He said: “This shows Grayling considers prison to be primarily about punishment, pure and simple.”