The judge’s ruling was the latest legal setback to Trump’s cost-cutting and government staff reduction drive.