The British government has paid out more than £14 million in three years to migrants who were thought to be in the UK illegally, after courts decided they had been detained unfairly.

The 573 recipients – who received on average more than £24,000 each – include migrants suspected of failing to leave the country on time, breaking the terms of their visa, or obtaining it by deception.

The largest group detained in the UK’s immigration centres are asylum seekers, and many of those receiving payouts were detained rightfully but held for too long. To receive the compensation, migrants must file litigation against the Home Office, often with the help of pro-mass migration charities.

The government stressed it had a responsibility to protect the public from those who might pose a risk of harm and said it regularly reviewed decisions to detain people. A spokesman told the Independent

“Detention is an important part of a firm but fair immigration system, helping to ensure that those with no right to remain in the UK are returned to their home country if they will not leave voluntarily.

“Decisions to detain or maintain detention are taken after careful consideration – and we are committed to treating all detainees with dignity and respect.

“The fact that a court may subsequently rule that an individual has been unlawfully detained does not necessarily mean the original decision was taken in bad faith. The court’s findings may only relate to part of the detention.”

Data from early 2016 shows that about 81 per cent of immigration detainees are held for less than two months, with some detentions spanning two to four months, and only a small number held for longer.

With immigration levels at a near record high, Home Office statistics show that the total number of people being detained for immigration offences is growing – hitting 32,400 last year.

According to the Independent, from 2009 to the end of 2015 between 2,500 and 3,500 migrants were detained at any one time. In 2015, 32,400 people entered detention, rising from some 30,400 in 2014.

Liberal Democrat leader Tim Farron, who uncovered the data, claimed the government was “locking innocent people up for administrative convenience” which was “a huge stain on our society and this adds insult to injury”.

In recent years, a coalition of left-wing, pro-mass migration organisations have been campaigning to close Britain’s immigration centres.

Trades union, Muslim, and feminist groups regularly march on the Yarls Wood illegal immigrant holding centre, demanding it is “shut down”.