"Police have opened an investigation to shed light on the death of the detainee, aged 36 and of Algerian citizenship," police said in a statement.
The man, who has not been identified, was found dead by staff Friday in his cell in a brand-new prison in the southern Spanish town of Archidona, near Malaga.
According to a police source, the man could not be revived. He had been placed in detention from November 20th to January 18th.
Migrants who arrive in Spain by boat are usually initially detained in police facilities for identification and processing before being sent to an immigration detention centre while their asylum claim is processed.
But the Spanish government has been housing nearly 500 migrants -- most of them Algerian -- in jails due to a lack of space at immigration detention centres, despite criticism from rights groups.
Authorities said the prison in Archidona had better facilities, including new showers, heating, beds and sports areas that could better accommodate migrants.
The prison is set to open its doors to prisoners next year.
The Jesuit Migration Service, which aids migrants at these centres, criticised the decision, saying it violated "rights and constitutional guarantees" and "unfairly criminalises people".
According to the International Organization for Migration (IOM), migrant arrivals by sea to Spain tripled in 2017 on the previous year, with almost 21,500 people arrivals between January 1st and December 20th, up from 6,046 during the same period last year.
The number of deaths is also up. So far this year 223 people have died or disappeared while trying to reach Spain by boat, 95 more than in 2016.