The three-judge panel backed the Labour government's appeal against the temporary injunction granted by a High Court judge last week that would have required the 138 asylum-seekers staying at the Bell Hotel in Epping, Essex, to leave by September 12.
The government was particularly worried that the High Court decision could have been a catalyst for other similar decisions around the country, which would have thrown its policies for housing asylum-seekers into disarray.
"We conclude that the judge made a number of errors in principle, which undermine this decision," Justice David Bean said.
"The judge's approach ignores the obvious consequence that the closure of one site means capacity needs to be identified elsewhere in the system."
The judge also warned that the ruling last week, in treating protests as relevant, risked "encouraging further lawlessness".
The government was joined by Somani Hotels, which owns the Bell Hotel, in challenging the temporary injunction that was granted on the basis of local planning laws.
Though local planning laws in Essex may not apply elsewhere, other councils, including Labour-run authorities, had publicly announced their intention to seek legal advice over whether they could achieve similar injunctions for hotels in their areas.
The government was criticised for pursuing an appeal, with many opponents arguing that it was putting the rights of asylum-seekers over those of local residents, a charge that it vigorously denies.
"Local communities should not pay the price for Labour's total failure on illegal immigration," said Kemi Badenoch, leader of the main opposition Conservative Party.
A small number of protesters donning the English and the UK flags gathered outside the hotel after the ruling, with police officers guarding its entrance, which was gated off with metal fencing.
The leader of Epping Forest District Council, which brought the case, voiced his disappointment at the outcome and set his sights on a full hearing on the matter that is set for mid-October.
Chris Whitbread told Times Radio that there had been both peaceful and "non-peaceful" protests outside the hotel, and said he supported peaceful ones.
"I call for calm," he said.
The Bell Hotel has become the epicentre for an issue that's topped the political agenda during the summer, following the sharp rise in the number of asylum-seekers arriving on small boats across the English Channel over the past few years.
For several weekends, protests have taken place outside hotels by both opponents and supporters of migrants.
Tensions became acute after a resident at the Bell Hotel allegedly tried to kiss a 14-year-old girl and was charged with sexual assault.
The man has denied the accusation and is currently standing trial.
Earlier Friday, Health Minister Stephen Kinnock said the immediate closure of asylum hotels could lead to migrants "living destitute in the streets" but that the government is looking for alternative ways to house the asylum-seekers.
The Labour government, which was elected a little more than a year ago, has struggled to curb unauthorised migration and fulfil its responsibility to accommodate those seeking refuge.
Using hotels to do so had been a marginal issue until 2020, when the number of asylum-seekers increased sharply and the then-conservative government had to find new ways to house them.
The number of asylum-seekers housed in hotels stood at just over 32,000 at the end of June, the Home Office said.
That figure was up eight per cent from about 29,500 a year earlier but far below the peak of more than 56,000 in September 2023.