Robert Fidler, 66, built four-bedroomed Honeycrock Farm in Salfords, Surrey, without planning permission in 2000 and, in 2002, his family moved into the property, which was kept hidden behind straw bales for four years.
Reigate and Banstead Borough Council ordered it to be knocked down in 2007 and Fidler's case was then rejected by a planning inspector, the High Court and the Court of Appeal.
The council began contempt of court proceedings after he failed to comply with the outstanding enforcement notices and an order which required demolition and to which he consented.
Yesterday, Mr Justice Dove at London's High Court said that Fidler would be jailed for three months for his "intentional defiance" unless he complied with the order by 6 June next year.
Fidler, who represented himself in court, claimed the council was out to "destroy" his life and that its case was based "on lies and deception".
He said his attempt to demolish the house was thwarted by the presence of bats and newts and that he had sold the property so it was no longer his responsibility.
The council had ruled out allowing the castle to stay because it breached national and local planning rules designed to protect the green belt.
Its counsel, Stephen Whale, said Fidler had deceived the authority for many years and had treated the planning system and the court with contempt.
Fidler, who was accompanied by his wife Linda and a number of supporters, left court without making a comment.
The judge said that Fidler's argument about the potential presence of protected species was misconceived - as this was not an absolute bar to demolition work - and the document relating to the purported sale of the property had no legal standing.
Describing Fidler as an "intelligent and determined man", the judge said: "This process has gone on now for many years. It is time now for those breaches of planning control to be remedied and that is what will happen. Otherwise there will be serious consequences."
Fidler was ordered to pay the costs of the hearing.