"That mechanism actually contributes to enabling Greece and Italy to deal with the impact of the 2015 migration crisis and is proportionate", a news release on the ECJ's ruling said.
European Union countries agreed in September 2015 to relocate 160,000 refugees in Greece and Italy over two years, but only about 24,000 have been relocated so far.
The agreement provided for the relocation of up to 160,000 people across member states, but only about 25,000 have been transferred so far.
A looming question is whether the commission will renew the relocation program in defiance of countries like Hungary.
According to the International Organization for Migration, 125,860 migrants and refugees have arrived in Europe by sea so far this year.
The European Commission warned EU member states earlier this year that there were "no more excuses" for not delivering on promises to take on refugees.
Beata Szydlo spoke on Wednesday after the European Court of Justice rejected efforts by Hungary and Slovakia to stay out of an EU scheme meant to relocate refugees from Greece and Italy.
"This decision jeopardises the security and future of all of Europe", Foreign Minister Peter Szijjarto said.
Hungary has not accepted a single asylum seeker since the measures were introduced two years ago.
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.
The low level of relocations, the ECJ noted, was partly due to "the lack of cooperation on the part of certain member states".
"This absolutely does not change the position of the Polish government with respect to migration policy", she said.
"We should not give in to threats, " he said.
Under the plan, Hungary must admit more than 2,300 asylum seekers, while Slovakia must in the long term take in 1,400.
"Due to the ongoing instability and conflicts in the immediate neighborhood of Italy and Greece, and the repercussions in migratory flows on other member states, it is very likely that a significant and increased pressure will continue to be put on their migration and asylum systems, with a significant proportion of the migrants who may be in need of global protection", the Court of Justice found Wednesday.
Mr Fico has made clear in recent weeks that he wants Slovakia to be close to a "core" of major European Union states, led by Germany and France, as they discuss plans for deeper future integration that are anathema to leaders in Budapest and Warsaw.