Judge William Alsup said citing "poor performance" for mass layoffs was "a sham in order to try to avoid statutory requirements," the New York Times reported.
Hearing a lawsuit brought by employee unions, Alsup ordered the departments of the Treasury, Veterans Affairs, Agriculture, Defense, Energy, and Interior to reinstate whoever had been fired improperly.
"It is a sad day when our government would fire some good employee and say it was based on performance when they know good and well that's a lie," Alsup was quoted as saying by the New York Times during a hearing at the US District Court in San Francisco.
After returning to the White House in January, Trump had ordered to fire thousands of federal employees as a part of his plan to cut spending programs.
His actions have faced several setbacks in courts with several judges issuing injunctions intended to halt them.