A legal bid to prevent failed asylum seekers being evicted without a court order has been dismissed.
The case against the UK Home Office and its contractor Serco was launched in the name of two women in Glasgow who were told their locks would be changed.
The move, which triggered a series of protests, was said to affect 330 others who had been refused refugee status.
Serco welcomed the Court of Session ruling but said it would not be taking any immediate action as a result.
Govan Law Centre, which launched the case, said it was "very disappointed" for its clients and for asylum seekers across Glasgow who have been threatened with lock-change evictions.
The 29-page opinion by Lord Tyre was published on the Scottish Courts and Tribunals website.
Govan Law Centre launched the case in August in the name of an Kurdish Iraqi national Shakar Ali and a Kurdish Iranian national Lana Rashidi.
The defenders in both cases were Serco and the Home Secretary but in Ms Ali's cases a third party, Serco's former sub-contractor Compass SNI Limited, was also named.
In his introduction, Lord Tyre said: "The principal issue that has been raised for determination in these proceedings is whether it is unlawful for Serco to evict an asylum seeker whose claim for asylum has been refused from his or her accommodation without first obtaining a court order authorising it to do so.
"I was advised that the two cases with which this opinion is concerned are regarded by all parties as representative of a larger number of cases in which the same issue arises."
The Home Office provides free, fully-furnished accommodation to asylum seekers while applications are being considered.
The contract is operated by private outsourcing firm Serco, which provides accommodation to about 5,000 people in Scotland, almost all of them in Glasgow.
When applications are refused, the asylum seekers no longer receive funding from the Home Office and Serco said it had picked up the bill, sometimes for months, without recompense.
The controversy dates back to last summer when it emerged six individuals had been issued with eviction notices that their locks would be changed.
Glasgow City Council leader Susan Aitken sent a "strongly-worded" letter to Sajid Javid, signed by politicians from several parties.
It condemned the Home Office contractor's action as "wholly unacceptable" and warned Serco's actions will "trigger a humanitarian crisis".
At the heart of the Court of Session bid was Serco's procedures covering lock changes, which the company described as its "Move On Protocol".
After considering all the issues, the judge concluded: "I am satisfied that neither of the pursuers has made out a relevant case for any of the orders sought."
Julia Rogers, managing director of Serco's Immigration business, said: "Serco notes today's decision by the Court of Session confirming our right to repossess property occupied by people whose claim for asylum has been determined by the UK government, but who nevertheless refuse to move on when asked to do so.
"In August 2018 we said that we unreservedly welcomed the legal challenge as it would enable all parties to clarify what was at that point an untested area of Scottish law.
"Today we have that clarity, and we are pleased that the Court of Session has confirmed our views on the legal position."
A Home Office spokesman said: "The Home Office takes the wellbeing of asylum seekers and the local communities in which they live extremely seriously.
"We have and will continue to work closely with local authorities and partners to ensure that those who have no right to be in the UK leave their accommodation in a safe and secure way.
"We are working with Glasgow City Council to agree and implement a support advice referral process for those at risk of potential eviction."
The Govan Law Centre described the opinion as "complex and comprehensive" and said it will take time to carefully consider the judgement.
Mike Dailly, solicitor advocate, said, following the court ruling, "any asylum seeker threatened with a lock-change eviction in Scotland will need to challenge that decision by lodging an urgent appeal to the First Tier Immigration Tribunal".
He added: "The practicalities of people being able to do so are challenging and not always straight-forward, and Govan Law Centre hopes to explore these serious challenges with partner agencies in Glasgow."
'Unfit for purpose'
Mr Dailly said it will still be necessary for people to first ask the Home Office for continued support and accommodation but if that is refused then it will be necessary to appeal.
A Glasgow City council spokesman said: "We will obviously need to take the appropriate time to consider a complex judgement - and to understand if there is likely to be any appeal.
"We now want to talk with Serco, the Home Office and third sector partners to work through any implications of the decision."
Jennifer Layden, convener of the council's asylum seeker strategic forum, said: "Asylum seekers in the city should know that, regardless of today's ruling, we will continue to press the Home Office for a firm commitment that we will not see a repeat of the kind of threats made by Serco last summer.
"We made it clear to both Serco and the Home Office that we did not expect to see them taking any immediate action following a decision in their favour - and I note today's public confirmation of that from Serco.
"That fact that the asylum accommodation contract and UK legislation allows for circumstances like these to arise demonstrates very clearly that they are not only unfit for purpose, but run contrary to the principles of compassion, welfare and community integration that Glasgow seeks to embrace as an asylum dispersal city."
In a joint statement the Scottish Human Rights Commission and Equality and Human Rights Commission warned dozens of people in Glasgow could be made homeless.
Judith Robertson, chairwoman of the SHRC, and Lynn Welsh, head of legal for the EHRC, said: "We remain extremely concerned about Serco's policy of locking people out of their homes without proper processes or safeguards, and the harsh impact this has on the people affected, leaving them with nowhere to go and in a vulnerable situation on Scotland's streets.
"We continue to have concerns that the policy fails to comply with people's human rights including their right to a private and family life."
Both said they will now consider the most appropriate next course of action, including possible legal intervention in another relevant case.
The statement concluded: "Today's judgment does provide welcome clarification that Serco has obligations under human rights laws when it comes to providing this accommodation and that the UK government cannot simply divest itself of its human rights obligations by outsourcing the provision of public services to private providers."
From September, Serco will no longer provide the housing after losing the asylum accommodation contract for Scotland.