The Polish government said in a statement: “The refusal to comply with the relocation mechanism was dictated by the need to protect Poland’s internal security and defend it against uncontrolled migration. The most important goal of government policy is to ensure the safety of our citizens.”

The Czech prime minister, Andrej Babis, said in response to the ruling: “We lost the case; it is not that important. Important is that we do not have to pay anything. The commission only applies refunds for the proceedings.”

“It is essential that we will not accept any migrants and that, meanwhile, the quota system was canceled,” he added. “And that is mainly thanks to us.”

The nationalist governments of the three countries previously cited national security reasons in refusing to take in any of the refugees and migrants. Prime Minister Viktor Orban of Hungary, for example, vowed to block the European Union program to resettle migrants from Africa and the Middle East, saying that it was important to secure his nation’s borders from the mainly Muslim migrants “to keep Europe Christian.”

Earlier this week, Mr. Orban came under severe criticism because of a raft of measures that were introduced ostensibly to combat the coronavirus but that effectively suspended the democratic process in Hungary.

Speaking at a news conference on Thursday, Ms. von der Leyen said she was “concerned that certain measures go too far,” and “particularly concerned about the situation in Hungary.”

“These emergency measures have to be limited to what is necessary,” she said. “They have to be strictly proportionate because they have to be adequate in this situation. They should not last indefinitely and, very importantly, they should be subject to regular scrutiny.”