Millions of pounds in compensation is being paid to migrants who have been traumatised after being locked up in detention centres across the UK, the Guardian has learned.

Government figures show £12m in "special payments" – including compensation – for 2009/10 and a further £3m the year before.

The Home Office said it did not record the proportion of special payments made in compensation, but officials accepted that the figure over the past three years ran to millions of pounds.

Lawyers who are acting for detainees said there was an "epidemic of mistreatment" in the asylum system.

Harriet Wistrich, of Birnberg Peirce, said there was a "systemic failure" to protect torture victims who came to the UK seeking refuge. "It is nothing short of scandalous that we are causing serious harm by detaining people, sometimes for long periods of time, who have done nothing other than seek a place of sanctuary from the horrors they have escaped from, in the mistaken belief that Britain is a just and tolerant society."

Shamik Dutta, of the law firm Fisher Meredith, said he had dealt with 15 or 20 cases in the past three years. "The callous and unlawful mistreatment of detainees is continuing, and is not just harming extremely vulnerable and damaged individuals but also costing the economy millions of pounds … it is clear there is an epidemic of mistreatment leading to civil claims going through the courts."

David Wood, strategic director for the criminality and detention group at the UK Border Agency, said the agency sought to exercise its power to detain people "reasonably and lawfully, [while] maintaining effective immigration control and protecting the public from harm".

The agency was largely successful in defending legal challenges to detention, he said, there could be "times when the courts conclude that detention is unlawful, and the agency is required to pay damages".

In one case this summer a Ugandan who had been tortured was awarded £110,000 after the court ruled he had been unlawfully detained in the UK for 10 months. The man, known just as Francis to protect his family in Uganda, fled to the UK in 2006. He said he had been beaten with sticks, burnt and hung upside down after being imprisoned in Uganda. He said he was also raped several times by guards.

"They did it many, many, times and when they were torturing me it felt like they wanted to kill me," he said. "The guards also set fire to a plastic jerrycan and let the burning plastic drip on to my head and shoulders. It is always with me, something that I always think about that I was tortured by rape … it is something that I really can't stop thinking about."

On arrival in the UK, Francis said, his medical report was lost by officials and then he was refused access to a doctor. "My experience of detention [in the UK] was terrible. The officials were rude and it felt as though they had been trained to refuse all asylum seekers. I told them again and again that I had been tortured, that I have given a report showing evidence of my wounds and answered all their questions but they did not seem interested. I thought this was a country that would protect me and would respect human rights and human dignity, but I have seen something different."

Wistrich, who was Francis's lawyer, said his treatment in the UK had exacerbated the post-traumatic stress he suffered after his torture in Uganda. "If Francis's case was the exception that proved the rule this would be bad enough but, unfortunately, I have seen many similar cases and from my anecdotal experience there is clearly a systemic failure to safeguard against the unlawful detention of torture victims."

In another case, in June this year, a woman from west Africa, who was locked up for a month in 2006 at Yarl's Wood detention centre, Bedfordshire, was awarded a £57,000 payout. In his ruling the judge said there had been a "grave failure" on the part of the Home Office. "A true punishment of the Home Office to reflect the gravity of the situation would run into sums far in excess of those which the court is legally authorised to award," he said.

In a separate case in August, a gay asylum seeker from Uganda was awarded £100,000 after the Home Office admitted breaking the law by deporting him and putting his life in danger.

Shami Chakrabarti, director of the human rights group Liberty, said: "Liberty is intervening in this case to end the detention of families with children and to press for an inquiry into deeply disturbing allegations of bullying and violence against some of the most forgotten vulnerable people in Britain."

Francis sought asylum in the UK in 2006 after being repeatedly tortured in his home country of Uganda. This year he was awarded £110,000 after the high court ruled he had been unlawfully detained in the UK for 10 months