A Transport for London spokesman said: "The High Court has found that we were right not to run the Core Issues Trust's advertisement as it would have breached Section 149 of the Equality Act 2010.
"The advertisement clearly breached our advertising policy as it contained a controversial message and was likely to cause widespread offence to the public.
"This was borne out by the hugely negative public reaction the advertisement generated, including on social media and newspaper websites.
"We are taking steps to address the judge's comments regarding our internal processes."
More top news
A Met Police officer was left red-faced after attempting to stop a cyclist riding along a dedicated cycle path.
The number of people allowed into official spectator areas will be cut by a fifth with just 100,000 tickets available.
The mayor was being challenged by Labour following his selection as the Tory candidate for the safe seat of Uxbridge and South Ruislip.