The inmates were treated inhumanely at the Edmonton Remand Center in Canada, according to an official report.
As well being made to wear the unhygienic underwear, they also suffered lice-infested bedding, poor air quality and terrible food.
Prisoners were also being locked two in a cell for between 18 and 21 hours per day, with limited access to recreational activities for months or even years.
Court of Queen's Bench justice Richard Marceau, in a new 285-page report, also condemned "unacceptable and discriminatory" racism by some warders - including a telephone ban for Asian inmates.
He said the treatment of Edmonton inmates "shocks the conscience and is grossly disproportionate".
Of the underwear policy, he wrote: "This does not accord with public standards of decency."
The center, built in the 1970s, is used for holding prisoners while they wait to go on trial.
Although it was initially meant for about 340 prisoners, more than 800 are now crammed into the facility.