Meant to last just two years, the measure adopted by the Council of the European Union calls for other EU member states to help relocate 120,000 migrants in need of worldwide protection.
Hungary and Poland voted against the plan and have refused to take part, while so far Slovakia has accepted only a handful of refugees from Greece.
The low level of relocations, the ECJ noted, was partly due to "the lack of cooperation on the part of certain member states".
"It is time to be united and show full solidarity", he added.
Hungary's prime minister, Peter Szijjarto, said after the ruling Wednesday that his government finds the decision "appalling and irresponsible".
"If relocation were to be strictly conditional upon the existence of cultural or linguistic ties between each applicant for worldwide protection and the Member State of relocation, the distribution of those applicants between all the Member States in accordance with the principle of solidarity laid down by Article 80 TFEU and, consequently, the adoption of a binding relocation mechanism would be impossible", the ruling states.
#ECJ confirms our view on the migration scheme.
Stanley Fischer steps down from Fed citing 'personal reasons'
I'm personally grateful for his friendship and his service. Rate increases are a sign that the economy is improving. Yellen's term as Fed chair ends in February.
"Politically, it enforces the concept of shared responsibility, which means backing for those countries that support distributions of asylum seekers", she said.
Human rights groups have criticized Hungary and Poland for their reluctance to take in any refugees.
Slovakia and Hungary argued the European Union broke its own rules and exceeded its powers when it approved the quota system with a "qualified majority", or about two-thirds vote. In September 2015, a razor-wire fence was constructed along the border with Serbia and Croatia, blocking migrants trying to reach the European Union via the Balkans.
Since 2015, millions of refugees war-torn and economically ravaged regions in the Middle East namely Syria, North Africa, and Asia have arrived in Europe, largely in Greece and Italy.
He described the court's decision as political.
"Given the tense politics of internal solidarity it might make more sense for the commission to avoid insisting on the commitment, having made its point", said Elizabeth Collett, the European director of the Migration Policy Institute, a research organization.
While Brussels expects previously non-compliant countries to accept refugees within weeks, Mr Szijjarto pre-empted a bitter stand-off by saying "all legal means" would be used to oppose the decision.