Southern District of Texas Judge Randy Crane lifted a restraining order that he had issued last month.
The DoD has approved GI Bill eligibility for National Guard troops stationed at the Mexico border after a year of confusion.
Mexico is not paying for the wall and, as of Nov. 1, Trump had built 78 miles.
For more than a year, the administration has placed several thousand active-duty troops along the border.
Mexico's President Andres Manuel Lopez Obrador said there is "great cooperation" to fight drug trafficking.
The stopgap spending bill would give negotiators four more weeks, pushing the possible shutdown to Dec. 20.
It is unclear what effect the ruling will have on the Marines' cases.
The representatives said they and 30 other lawmakers sent a letter to the Pentagon IG requesting an investigation.
Paying for the border wall and the U.S. troop presence has become a major roadblock to passage of the defense budget.
"They snuck him out in the middle of the night," said Texas attorney Tom Sanchez.