The government has agreed to pay thousands of pounds in damages to two severely disabled men whose benefits were wrongly reduced when they were forced to sign up to universal credit after moving house.

A high court ruling in June found the Department for Work and Pensions had unlawfully discriminated against the men when it docked their benefits by about £170 a month.

The DWP had initially resisted making the details of the compensation settlement public, but it gave in on Monday after coming under pressure from the judge in the case, who accused the department of trying to hide something.

“You are the government, and we should know what you are doing and what you are spending,” Mr Justice Lewis said.

The two men, known for legal reasons as TP and AR, received £6,517 and £4,788 respectively, in compensation for the “pain and distress” caused. They will also receive £173.50 and £176 a month respectively to meet the continuing shortfall in their benefits.

Both men had been in receipt of the severe disability premium and enhanced disability premium – supplementary benefit payments designed to meet the extra costs of living alone without a carer. An estimated 500,000 people in the UK receive one or both payments.

Although they were advised by the DWP that their payments would be protected when they moved into a universal credit area, both TP and AR had their income reduced by £178 a month when they signed up to the new benefit.

AR, 36, who has a severe mental illness, went on to universal credit when he moved from Middlesbrough to a cheaper property in Hartlepool after being affected by the bedroom tax. TP, a former City worker who was diagnosed with a terminal illness, was shifted on to the new benefit when he moved to Hammersmith and Fulham to receive medical treatment.

In a witness statement to the court, TP said constant money worries had made him more isolated, anxious and depressed. “The stem-cell transplant and chemotherapy was very gruelling and the anxiety around my finances and universal credit has made it all a lot worse,” he said.

“This reduction in my income came at the worst time it could have done. I know it has had a detrimental effect on my wellbeing and I believe it hindered my recovery, as it caused me a great deal of stress.”

Lawyers representing the two men said they hoped the DWP would compensate thousands of other disabled claimants who have been wrongly docked disability benefit entitlements after moving on to universal credit.

Although the DWP agreed to pay compensation in this case, it is currently applying to challenge the June ruling in the court of appeal.

Tessa Gregory from the human rights team at the law firm Leigh Day, who represented the two men, said: “We are pleased that the secretary of state has agreed to compensate our clients for the unlawful discrimination they have suffered.

“Both of our clients suffered significant hardship because of the sudden reduction to their income when they were transferred to universal credit.”