The ruling preserves, for now, billions of dollars in grant money for 23 states and the District of Columbia.