HONG KONG — President Trump’s public criticism of a federal judge who blocked his immigration order was condemned across the political spectrum as an assault on judicial independence. Now the president is being taken to task from an unexpected place: China.

Judge He Fan of the Supreme People’s Court of China published a scathing blog post about Mr. Trump’s reaction to Judge James L. Robart’s recent ruling blocking key parts of his executive order that barred visitors from seven predominantly Muslim countries. Judge He said that Mr. Trump had breached the principle of an independent judiciary, and that people who attacked judges were “public enemies of the law.”

“Even if you control the armed forces and have nuclear weapons,” Judge He wrote in the post, published on Sunday, “your dignity has been swept away and you are no different than a villain.”

The notion of a Chinese jurist remarking on the danger he believes Mr. Trump poses to the separation of powers may seem, at first blush, to smack of hypocrisy. In China, courts are firmly under the command of the Communist Party. Last month, the chief justice publicly condemned the notion of judicial independence, warning judges not to fall into the “trap” of “Western” ideology.