Well, I understand that it seems logical that what is properly registered in the property registry is legal, but it is not.
Until a few years ago anyone could go to a Notary, make an inscription of new work ( called Obra Nueva) stating that they had a house and then the Property Registrar would register it in the Land Registry without asking for a plan or a licence.
In this case, the construction appears today registered and yet it never had a license.
Nowadays it is not so easy anymore; when someone goes to the Notary to declare a new building and does not have a license, the Notary warns in the deed of the lack of license. The property registrar informs the administration that a construction without a licence has been registered.
If the construction is more than 8 years old and the right to order demolition has expired, it is registered and the authorities do nothing because they can no longer do so.
A house that is illegal is registered.