Three Afghan refugees took legal action over conditions at Brook House IRC, near Gatwick Airport.
The men said detainees were locked in their "cells" between 21:00 and 08:00 every day.
In a judgment delivered remotely, Mr Justice Cavanagh dismissed their claim on all grounds.
The claimants, who have all now obtained refugee or humanitarian protection status, were detained at Brook House in 2017 or 2018, when the centre was run by G4S.
They claimed the "lock-in regime" at Brook House, which the Home Office refers to as "the night state", breached their right to liberty and privacy.
It was also said the regime subjected them to "an unlawful, discriminatory and/or disproportionate interference" with practising Muslims' right to religious freedom as they had to pray in their cells overnight.
Mr Justice Cavanagh ruled that "by deciding that there should be a night state, the (Home Office) was striking a lawful balance between the statutory purposes of security, safety and good order and the statutory purposes of providing a relaxed and humane environment".
He also found the Home Office "took reasonable and appropriate measures to secure Muslim detainees' rights".
Conditions at Brook House have been under scrutiny since a BBC Panorama programme broadcast in September 2017 uncovered footage showing alleged assaults, humiliation and verbal abuse of detainees by officers.
Fourteen members of G4S staff were dismissed or resigned following the broadcast and Home Secretary Priti Patel later announced a public inquiry to investigate the "mistreatment of detainees" at the centre.
Three detainees have gone on hunger strike at the removal centre ahead of proposed removal flights to France, Spain and Germany.