The EU top court said Budapest made it virtually impossible for people to make an asylum claim.
Hungary failed to comply with EU law by restricting access to the international protection procedure and returning migrants to a border area, the European Court of Justice ruled on Thursday.
The Luxembourg-based court said that third-country nationals wishing to claim asylum in Hungary "were in practice confronted with the virtual impossibility of making their application" due to national legislation making it mandatory for them to start the procedure from a so-called transit zone and an administrative practice "drastically" limiting the number of people allowed to enter these areas every day.
It also confirmed an earlier ruling that said Hungary forcing applicants to remain in one of the transit zones for the duration of the procedure "constitutes detention".
The court flagged that EU law dictates detention can only be ordered "in writing with reasons", that adequate support must also be given to applicants identified as vulnerable, and that minors may only be detained as a last resort.
"Owing, in particular, to its systematic and automatic nature, however, the detention regime provided for under Hungarian legislation in the transit zones, which concerns all applicants other than unaccompanied minors under 14 years of age, does not allow applicants to enjoy these guarantees," the court said in its judgement.
It rejected Budapest's argument that the migratory crisis justified derogating from certain rules and also found that the country flouted an EU directive over the return of illegal migrants.
It found for instance that police officers forcibly escorted third-country nationals illegally staying in the country to the other side of a fence erected a few metres from the border with Serbia, "to a strip of land devoid of any infrastructure", without prior compliance with the procedures and safeguards provided for in the directive.
Additionally, Hungary did not respect the right of third-country nationals to remain in the country after the rejection of their application, until the time limit within which to bring an appeal against that decision or, if an appeal had been made, until a decision has been taken on it.
Hungarian Justice Minister Judit Varga said in response to the ruling that it is "devoid of purpose, as the circumstances at issue in the present proceedings no longer exist. Transit zones have been closed but strict border control is maintained."
"We will continue to protect the borders of Hungary and Europe and will do everything we can to prevent the formation of international migrant corridors," she added in a Facebook post.
However, the ECJ said in its judgement that the closure of the transit zones following a preliminary ruling "has no bearing on the present action, the situation falling to be assessed at the date laid down by the Commission in its reasoned opinion for addressing shortcomings, namely 8 February 2018."
The EU's Home Affairs Commissioner, Ylva Johansson, stressed following the ruling that "Member States must ensure that persons concerned are able to make an application of international protection, including at the borders, as soon as they declare their wish to do so.
"The New Pact on Migration and Asylum is built on this fundamental principle. The Court also makes important clarifications of the rules concerning detention and return," she added.
Hungary has outright opposed Brussels' proposed Migration Pact, alongside Poland and the Czech Republic. The plan aims to streamline the migration and asylum process with faster screening and to have member states contribute their "fair share" based on their GDP and population.
The number of first-time asylum applications in EU member states has drastically fallen since a 2015 peak of nearly 1.3 million. That year, Hungary received more than 177,000 applications, second only to Germany's 476,510, according to Eurostat.
But contrary to Berlin, which logged more than 745,000 new applications the following year, Budapest divided its number by more than six with Austria, France, Greece and Italy all registering more applications.
In 2019, the 27 countries of the EU collectively received just under 700,000 first-time asylum applications, of which only 500 were filled in Hungary.