Hard-line Christians are claiming an "important victory" in the row over their controversial "gay cure" bus adverts.
The Court of Appeal demanded an investigation into Boris Johnson's actions in banning the posters.
Designed for the sides of London buses, they 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!''
A legal action brought by the Core Issues Trust charity accuses Johnson of unlawfully using his position as chairman of Transport for London (TfL) to obtain the ban of the Christian ad to secure the gay vote and advance his 2012 re-election campaign.
It has already been rejected by the High Court. But on Monday morning, the Court of Appeal said there must be a further investigation to reconsider whether the mayor had acted "for an improper purpose".
Johnson argued the Core Issues ad was ''offensive to gays'' and could lead to retaliation against the wider Christian community.
His office welcomed the ruling, saying: "The Mayor is pleased TfL’s original decision to ban the Core Issues Trust advert has been upheld by the Court of Appeal.
"He agreed with TfL’s ban at the time and will continue to support the banning of adverts that breach advertising policy and cause widespread public offence, as this advert clearly did."
But the Christian Legal Centre and the Core Issues Trust hailed a "significant victory", pointing to questions over the mayor's involvement.
Andrea Minichiello Williams, of the Christian Legal Centre, said: "In a mature democracy both sides of a debate should be heard but it seems that Boris Johnson, Transport for London and Stonewall are intent to shut down the Christian side of the debate by fair means or foul."
The Master of the Rolls Lord Dyson, sitting with Lord Justice Briggs and Lord Justice Christopher Clarke, declared: "It is not possible to reach a conclusion on the question whether TfL's decision not to allow the Trust's advertisement was unlawful on the grounds that it was instructed by the mayor or made made for an improper purpose.
"I would, therefore, remit the case for the judge (Mrs Justice Lang) to reconsider this question in the light of fresh evidence and in the light of any further material that emerges as a result of the directions that she may give."
Lord Dyson said that if after reconsideration "the judge decides that the decision was not instructed by the mayor and not made for an improper purpose, then her decision (upholding the ban) will stand".
However, if the judge decides that the decision was instructed by the mayor or made for an improper purpose, "then the decision must be quashed."