Transport for London had refused to carry the ad on the grounds that it was "likely to cause widespread or serious offence to members of the public", and it contained "images or messages which relate to matters of public controversy and sensitivity".
Today the judge backed the TfL stance, despite her finding that there had been unfairness in its procedures.
The judge said TfL had applied its advertising policy "inconsistently and partially", but its refusal to display the gay ad was "justified and proportionate, in furtherance of the legitimate aim of protecting the rights of others".
More top news
George Osborne told MPs London would shoulder a large part of his 37% reduction in transport funding.
The prison was originally opened in 1852 as a mixed prison before becoming the first female-only local prison in England in 1902.
A man who tried to help a woman, who was being assaulted by other passengers on the Victoria Line, ended up being punched in the face.