The High Court ruled Transport for London's process in introducing the ban "was procedurally unfair".
But it ruled TfL was acting lawfully in banning the Core Issues Trust's proposed advert because it would "cause grave offence" to those who were gay.
The posters read: "Not Gay! Ex-Gay, Post-Gay and Proud. Get over it!"
They were a response to a bus poster campaign by gay rights group Stonewall, which carried the message: "Some people are gay. Get over it!"
The High Court's ruling also said the Stonewall advertisement was "highly offensive to fundamentalist Christians and other religious groups whose religious belief is that homosexuality is contrary to God's teachings".
A judge ruled Boris Johnson did not abuse his position as chairman of TfL when he imposed the ban.
The Core Issues Trust said the London mayor was "politically driven" when he intervened to block the ad, which suggested gay people could be helped to "move out of homosexuality".
Mr Johnson condemned the "gay cure" advert as "offensive to gays" and said it could lead to retaliation against the wider Christian community.