Community Pharmacies (UK) Ltd had hoped to move the Superdrug branch in Derby's intu shopping centre to a GP surgery on Wilson Street, 600m away.
The NHS blocked the move because “the surgery would be less accessible to women seeking emergency contraception”.
Mr Justice Langstaff dismissed the pharmacy firm's challenge stating that the NHS was entitled to take into account the particular needs of women.
An NHS panel said many of Superdrug's customers were young women and there was a risk they would be inconvenienced by the move.
It added the obvious route to the new location would pass a homeless night shelter at Milestone House, on Green Lane.
The health service raised concerns some of those seeking shelter there would be suffering from drug or alcohol problems and "might indulge in anti-social behaviour or begging".