If it were subsequently declared illegal, wouldn’t the blame (and repercussions) extend to the Notary who is there to see all paperwork is correct, and to the Ayuntamiento who have received the taxes and maybe the Land Registry who registered the purchase?
Otherwise, couldn’t you argue that the Notary was in receipt of funds from an illegal operation; the Ayuntamiento accepted funds from an illegal source; the Land Registry were guilty of accepting money derived from illegal activities?
Logically you are correct, however non of that may may apply in Spain.
Thats the whole issue that the EU has with Spain, its legal system allows all the guilty parties to get off with any penalty, the person who suffers is the home buyer. Don’t kid yourself that your building won’t be demolished, certainly people should consider very carefully investing in a country where this CAN happen.
BTW, avoid N. Cyprus, buying an illegal property could land you with a 5 year jail sentence and cost your UK house as well.