The European Union approved the controversial scheme two years ago as it grappled with Europe's worst migrant crisis since World War II, but Hungary and Slovakia went to court to block the plan, backed by other eastern member states.
European Home Affairs Commissioner Dimitris Avramopoulos had said he regretted how certain member states "continue to show no solidarity and to ignore our repeated calls to participate in this common effort".
"Today's ruling shows that no country can hide from their responsibilities to refugees", Iverna McGowan, Director of Amnesty's European Institutions Office, said in a statement.
Hungary's prime minister, Peter Szijjarto, said after the ruling Wednesday that his government finds the decision "appalling and irresponsible".
Andrew Luck 'unlikely' to play Week 1
Scott Tolzien would be poised to start at quarterback in the September 10 opener if Luck is not able to play. That said, there still isn't a timetable to when Luck will make his return to the field.
In their legal challenge Hungary and Slovakia argued at the ECJ that the policy exposed them to the risk of Islamist terrorism, because numerous migrants are Muslims.
Only around 24,000 people have been relocated so far.
His comments came after court dismissed the actions brought by Slovakia and Hungary against the provisional mechanism for the mandatory relocation of asylum seekers to relieve pressure on front-line countries.
Hungary, Slovakia, the Czech Republic and Romania opposed the plan, arguing they were not equipped to integrate people from mainly Muslim countries. "This decision jeopardises the security and future of all of Europe".
'Everyone Deserves a Chance': Silicon Valley Reacts to Trump's DACA Decision
All the while, his administration has continued to issue new permits and extensions to immigrants who qualify. Still, he added, "we must also recognize that we are nation of opportunity because we are a nation of laws".
Human rights groups have criticized Hungary and Poland for their reluctance to take in any refugees.
The ECJ's decision responded to a complaint by Hungary and Slovakia over the legality of a September 2015 Council decision to distribute asylum seekers from Greece and Italy across the bloc, based on quotas established by the European Union commission.
"We fully respect the verdict of the European Court of Justice", Slovakian Prime Minister Robert Fico told outlets including the AP.
Poland, which has not lodged a complaint with the ECJ, nor did it vote against the measure in 2015 under its previous government, also vowed not to change its opposition to the quota policy. "Under the policy, Hungary is required to take in 1,294 refugees and Slovakia 902".
Based media watchdog seeks probe in Gauri Lankesh's murder
He also said his government had an "open mind" to an investigation by CBI, which the slain journalist's family has demanded. The Minister accused Chief Minister Siddaramaiah of not taking previous sensitive criminal cases seriously.
Slovakia is not included in the legal action as it recently agreed to host a few refugees. While the flow of Syrian refugees has slowed somewhat since a deal was signed with Turkey, the question remains of what to do with the ones that have already arrived. So far only 25,000 refugees have been moved.