The court ruled in favour of an appeal by Prime Minister Mariano Rajoy's conservative government, which argued that the law passed by the left-wing regional government of Andalucia interfered with powers alloted by the constitution to the central government.
The law which came into force in April 2013 allowed the regional government of Andalucia, Spain's most populous region, to expropriate properties from which people are about to be evicted for up to three years to allow them to continue to live there.
The law allowed the regional government to act only in cases where families meet certain conditions, such as having a net monthly income of less than €1,600 ($1,750).
The government of Andalucia argued the measure is needed to protect the most vulnerable amid a sharp rise in evictions in a region where one in three workers is unemployed but the central government saw the law as an attack on private property rights.
Home evictions have soared in Spain since a property bubble collapsed in 2008, throwing millions of people out of work.
Authorities seized 95 homes a day in 2014 from inhabitants who defaulted on their mortgage payments, according to official data.
On top of that were countless other families evicted for defaulting on rent or for occupying vacant properties.
A series of suicides by people about to be evicted and regular television images of weeping families who have just been thrown out of their homes has pushed the issue to the top of the political agenda.
Ada Colau, who became a household name in Spain fighting foreclosures by physically trying to block police from serving eviction notices at people's homes, was elected mayor of Barcelona on Sunday.
Colau and the top candidate to become mayor in Madrid following weekend local elections in Spain, retired judge Manuela Carmena, have both vowed to make fighting evictions their top priority.
Andalucia has been especially hard hit by the economic crisis.
It had a jobless rate of 33.6 percent in the first quarter. Only Spain's tiny north African territory Melilla had a higher unemployment rate.