The ruling is the latest rebuke of the president’s effort to halt grants approved by Congress.