The 17 states are all led by Democratic attorney generals and joined Washington DC to file the lawsuit in federal court in Seattle.
The ruling directly debunked the fiction, peddled by Attorney General Jeff Sessions and Homeland Security Secretary Kirstjen Nielsen, that the separation of immigrant children from their parents is akin to procedures that apply when USA citizens commit crimes.
Azar testified before Congress on Tuesday where, according to the Washington Post, he told the lawmakers that if they wanted kids returned to their families, it would have to come as part of legislation.
"The unfortunate reality is that under the present system migrant children are not accounted for with the same efficiency and accuracy as property", wrote the judge, noting that immigrants are given receipts for confiscated goods or cash, but not so much as a chit for a wailing child hauled off to who knows where.
On Monday, Trump continued trying to make his case, in yet another typo-filled tweet, for denying constitutional protections for undocumented immigrants.
The border official's decision paves the way for U.S. immigration enforcement to revert largely to the approach under the Obama administration.
On Monday, White House press secretary Sarah Sanders said the reality was that the US did not have the space to hold all the undocumented families coming across the US-Mexico border.
"But we can't forget: The lives of real people hang in the balance".
"What he (the President) is doing with families on the border, separating children, violates the Constitution", New York Gov. Andrew Cuomo told CNN's Wolf Blitzer earlier on Tuesday.
"This clear call for an end to the constitutionally-guaranteed right to due process is symptomatic of an administration that disdains both the Constitution and our judicial system, and would subject those who cross our borders to the whims of unaccountable officials acting on the twisted logic of white supremacy and racism", Nihad Awad, CAIR national executive director, said in a statement.
Immigration authorities have separated about 2,300 children from their parents in recent weeks, sparking global outrage as images and recordings of weeping children emerged.
"I can not reunite them, though, while the parents are in custody because of the court order that doesn't allow the kids to be with their parents for more than 20 days", he said.
A US judge in San Diego already is considering whether to issue a nationwide injunction sought by the American Civil Liberties Union that would order the administration to reunite the separated children with their parents.