The 42-year-old asylum seeker received "truly disgraceful" treatment from the British government, resulting in further damage to her health when she spent 37 days in an English detention centre between December 7, 2013 and January 13, 2014.
In a case brought against Home Secretary Theresa May, Mr Justice Collins said there was strong medical evidence that the woman, identified only as "IKM" for legal reasons, had been subjected to brutal treatment in Sudan.
He said: "Very properly the secretary of state has conceded her detention was unlawful.
"It is well known that she was someone who in all probability had sustained torture and that meant she was someone who should not be detained unless there were very exceptional circumstances. There were none.
"It damaged her health to such an extent that on her eventual release from custody she had to spend three weeks in hospital.
"It is, I hope, a unique case because the behaviour of those responsible was utterly unreasonable and truly disgraceful."
The court heard that IKM, a non-Arab from Darfur, worked as an accountant in Khartoum.
In 2004 Janjaweed militiamen were responsible for killing her father and kidnapping her mother and she went back to Darfur to take care of her family.
When she returned to her home village with her fiance, he was killed in another Janjaweed attack and she was shot in the leg and raped.
She suffered a series of brutal attacks before she managed to escape and travelled to England to study. However, she then decided to claim asylum in the Republic of Ireland in the belief she could not claim in England because she possessed a student visa, the judge said.
IKM's asylum claim was rejected and her appeal dismissed in 2010, the Press Association reported. She made her way back to England via Belfast to an area in the north east where she gained the support of a local Sudanese community.
However, the Home Office certified that she should be returned to the Republic of Ireland.
Officials concluded it was for the Irish authorities, despite them having refused her asylum, to consider further whether there were humanitarian reasons to give her refuge.
The judge said that IKM's story of rape and torture was consistent and credible, and up to five different doctors all agreed she was suffering from post traumatic stress disorder and the flashbacks she was suffering were "not in the least surprising".
The judge added: "In circumstances such as these, it is difficult to see this as other than a cast iron case for asylum in this country.
"The secretary of state should seriously consider whether it really is humanitarian to require the Dublin Convention provisions to be followed, rather than adopting a compassionate approach in the particular circumstances of this case."
It will be down to the Home Secretary to make a final decision on whether IKM should be allowed to stay.
It is still open to her to appeal the ruling to the appeal court.