The ruling is a win for the administration against a judge whom the president has sought to fashion into an adversary.