A Spanish man, 59, has been freed after spending almost 20 years caged in “inhuman conditions” in a three-metre pigeon coop, allegedly at the hands of his family.

Spanish police raided a property in the southern town of Dos Hermanas outside Seville on Wednesday (AEDT).

They found the mentally ill man naked on a filthy mattress with only a bucket for a toilet, Agence France-Presse reported.

“His health and cleanliness were deplorable and the state of the place was completely insanitary … without access to running water or toilets,” police said in a statement.

• Husband, wife guilty of plot to bomb London

• Glee star arrested on suspicion of child porn

The man’s brother, 76, and sister, 61, were arrested on suspicion of unlawful detention and abuse.

Police suspect the pair of holding their sibling captive since 1996, as that was the last year he attended a medical checkup.

It is unclear why the police entered the property.

The cell containing the man was reportedly a dovecote — a structure designed to cage doves or pigeons. Police said it adjoined the house in which the brother and sister lived.

It was reportedly accessed by two doors barred by a padlock, chain and wooden beam.

“Due to the strange situation they were faced with, the agents asked both siblings to open the … door to check the state of their brother,” police said in the statement.

“After going through both doors, they found a crumbling, narrow staircase that went up to a type of dovecote.”

The brother claimed the caged man was kept in the room because of his mental illness, police said.

The man is reportedly being treated in hospital.