WARSAW — When President Trump visited Warsaw in the summer of 2017, the Polish government was busy setting up a transformation of the nation’s judicial system in ways that critics found deeply troubling and undemocratic.

Opponents of the overhauls hoped that Mr. Trump would use his visit to urge the government to change course. He did not. Instead, greeted by cheering throngs — many bused in from rural villages where the governing party’s support runs deepest — he warned of the dangers of “radical Islamic terrorism” and “the creep of government bureaucracy.”

“It seems to me it was a green light to push ahead with the radical reforms,” said Adam Bodnar, the Polish ombudsman, a state entity that protects civil liberties.

Now, as President Andrzej Duda sets off for his first official visit to the White House on Tuesday, the project to reshape the courts is nearly complete after a purge of the Supreme Court through the forced retirements of one-third of the justices.