Estate agency, Maxwell Estates Limited, occupied the ground floor and basement of 85 Newington Green Road in Islington, which had an established use for the provision of financial and professional services.
However, in early 2013, the court heard, the basement was turned into a flat, by installing a shower, kitchen sink and domestic units, and was let to a tenant in April 2013 for £750 a month.
Mrs Justice Lang said that "no planning permission was sought" for the change of use and the basement was not registered separately for council tax.
After the tenant moved out in October 2013, the flat was "gutted" and extensively renovated before being re-let in May the following year.
During the works, Islington Council argued the basement was reduced to an uninhabitable "shell unit" and would not have been recognisable as a residential flat.
The council eventually received a third-party tip-off about the alleged breach of planning control and, following an investigation, issued an enforcement notice in January 2018. Maxwell Estates was required to cease residential use of the basement and to return it to its former business use.
The company, however, succeeded in its appeal to a government planning inspector in March this year (DCS reference: 200-008-345) and the enforcement notice was overturned.
The inspector rejected claims that Maxwell Estates had "deliberately concealed the existence of the change of use of the basement" which had been openly advertised to flat-hunters.
Crucially, he ruled that the basement had been in continuous use as a dwelling from at least April 2013 - more than four years before the notice was issued.
That meant that, by operation of section 171B(2) of the Town and Country Planning Act 1990, the change of use had become immune from enforcement action.
He rejected the council's arguments that, due to the "break in occupation" caused by the renovation works, time only began to run in May 2014.
Mrs Justice Lang, however, today overturned that decision, ruling that the inspector had failed to follow precedents set by the Court of Appeal in two test cases.
Those decisions gave authoritative guidance on the correct approach to cases in which immunity from enforcement action is claimed due to lapse of time.
Directing the Secretary of State for Housing, Communities and Local Government to consider the matter afresh, the judge concluded: "The inspector misdirected himself in law and misapplied the relevant law."