Hungary was accused on Thursday of holding asylum seekers in a camp on the border with Serbia in "unlawful detention" by the Advocate General of the European Court of Justice (ECJ).
The case relates to four migrants from Iran and Afghanistan whose asylum applications were rejected by the Hungarian authorities.
The four men have been held in a camp in Roszke, on the border with Serbia, a transit country that also refused to readmit them.
They took the case to the ECJ believing their treatment was contrary to a European Union directive dating from 2013 on the reception of refugees.
After examining the case, Advocate General Priit Pikamae agreed with the four migrants.
Serbia's refusal to take them should have led Hungary to resume "the procedure to examine the substance of their initial asylum request", rather than order their expulsion to their country of origin, the ECJ said in a statement.
Pikamae criticized the conditions in the "safety transit area" of Roske, saying it constituted "unlawful detention" under the EU directive.
"Asylum-seekers accommodated there are physically cut off from the outside world and forced to live in a situation of isolation," said the statement which also criticized the "high degree of restriction of the freedom of movement... It constitutes detention".
Since the EU migration crisis in 2015, the Hungarian government has repeatedly come under fire from Brussels over the issue.
Orban's anti-immigrant government is opposed to taking in refugees and erected a fence -- electrified in some places -- along Hungary's border with both Serbia and Croatia.
"The detention of the asylum seekers in question must be classified as unlawful," Pikamae said.
Barbara Poharnok of the Hungarian Helsinki Committee, the country's main human rights organization, said the Advocate General's opinion "gives hope to people who have been detained for a very long time in these transit areas, including over a hundred children, that Hungary will finally study the merits of their asylum requests".
The court, based in Luxembourg, is not bound by the opinion of the Advocate General and is expected to deliver its judgment in several weeks.