The northeastern region vowed to push on with the vote, however, defying fierce resistance from the national government, which has called for unity as Spain crawls out of its economic crisis.
Under Spain's constitution a region "cannot unilaterally call a referendum on self-determination to decide on its integration in Spain", according to a written summary of the ruling released by the Constitutional Court.
It ruled "unconstitutional and null" a declaration by the Catalan regional parliament which claimed Catalonia had a sovereign right to hold a vote on its future.
The court upheld a legal challenge by the national government to that declaration and said any "right to decide" by Catalans could only be exercised in accordance with Spain's 1978 constitution, which insists on the unity of Spain.
Leaders in Catalonia have called the referendum for November 9 to ask Catalans whether their region should be a separate, independent state.
Many Catalans have drawn a comparison with Scotland, whose leaders are holding a referendum in September on independence from Britain -- a move authorised by the British government.
Spain's conservative Prime Minister Mariano Rajoy has argued that Catalonia cannot hold a referendum like Scotland because Spain, unlike Britain, has a written constitution that rules out such a move.
Rajoy insisted last month that the referendum "can't take place".
"No one can unilaterally deprive the entire Spanish people of the right to decide on their future," he told the national parliament, which is due to debate the referendum issue on April 8.
Tuesday's ruling poses a setback for Catalonia's president Artur Mas, who has said he is determined to hold the vote legally.
The Catalan government insisted shortly after the ruling that it would not derail the drive for a referendum, however.
"This will have no effect on the process," its spokesman Francesc Homs said on Catalan television.
- 'We will not budge' -
The leftwing ERC party, one of the rival groupings that united with Mas in calling the referendum, echoed that defiant note.
"We will not budge from our commitment to hold polls on November 9," its parliamentary spokesman Pere Aragones said in a statement.
The referendum is opposed by Spain's two largest national parties: the ruling conservative Popular Party and the main opposition Socialist Party.
Proud of their distinct language and culture and fed up after five years of stop-start recession, many in Catalonia want to redraw the map of Spain, saying they feel short-changed by the central government, which redistributes their taxes.
Catalonia is home to 7.5 million of Spain's total population of 46 million people. It accounts for more than a fifth of Spain's economic output and a quarter of its exports.
On September 11 last year, Catalonia's national day, hundreds of thousands of Catalans massed in a vast human chain stretching across the region to demand independence.
The national day recalls the conquest of Barcelona by Spanish king Philip V's forces in 1714.
Catalonia was there at the symbolic birth of Spain when Queen Isabella of Castile and King Ferdinand of Aragon, a region that included Catalonia, married in 1469.