Upholding a legal complaint from the 18-year-old known as Carlos, the court said the youth should be released within ten days from the closed unit where he is being held, according to the Swiss news agency SDA.
It overturned the original ruling by the Zurich high court that had ordered his detention.
Carlos was admitted to the unit after public outrage when media revealed his therapy programme allowed him to live in a four-room apartment at a reported cost of 29,000 francs a month.
In its ruling the Federal Court said Carlos’s “special treatment” had been broken off abruptly under public and media pressure, and had nothing to do with his behaviour.
It ordered the Zurich authorities to find an alternative to detention in the closed unit.
The youth has a history of violent offences, and stints in juvenile detention and treatment in a psychiatric hospital reportedly failed.
His case came to light last August in the public affairs show “Reporter” on SRF, the German-language state broadcaster.
The programme revealed that the youth was supported by a 10-person team.
Media subsequently reported that the canton of Zurich had spent 960,000 francs on Carlos and his entourage of a social worker, lawyer and Thai boxing coach.
Carlos was charged with a string of offences including robbery, weapons possession, drug use, threats and assaults.