For children under five, reunification must take place within two weeks of the order issued Tuesday by US District Judge Dana Sabraw in San Diego, AFP reported.
Sabraw made the sternly worded decision in response to a suit filed by the American Civil Liberties Union on behalf of a seven-year-old girl who was separated from her Congolese mother and a 14-year-old boy who was separated from his Brazilian mother.
The judge also issued an injunction against any more family separations, which was part of a policy under which anyone crossing the border illegally is detained and referred for criminal prosecution.
US federal authorities have 10 days to allow parents to call their children if they are not already in touch with them, the judge said.
Trump last week signed an executive order halting his government's practice of taking children away from parents who cross the border without papers, even to seek asylum. Many are destitute people fleeing gang violence and other turmoil in Central America.
It was a rare retreat for Trump, who has made fighting immigration – both illegal and legal – one of the most sacred mantras of his fiercely US-centered policy agenda.
But the order made no specific provisions for families already separated under the policy, which sparked heated criticism in America and worldwide as inhumane and even a form of child abuse.
More than 2,000 children taken from their families remain under the care of federal authorities. Some are just toddlers, or even infants.
The ACLU argued that the administration has no real plan for reuniting families.
Now, the policy of detaining parents who cross illegally with children has been suspended, with authorities saying that among other factors they do not have space for all the families coming over from Mexico.
The attorneys-general of 18 mainly Democratic states also filed a lawsuit Tuesday challenging the Trump family separation policy.
They argued that Trump's order halting the practice has so many caveats it is meaningless. It calls for money to be appropriated to reunite families but does not say how much or by when, and depends on a judge allowing indefinite detention of children, the officials wrote.
"Keeping children separated from their parents is inhumane, unconscionable and illegal – and we're filing suit to stop it," wrote Attorney General Barbara Underwood of New York.
Some 200 protesters turned out in Los Angeles to protest a visit by US Attorney General Jeff Sessions, one of the most visible faces of the Trump border control policy.
Around 20 were arrested after defying police orders to disperse.
Trump did score a big win on immigration Tuesday, however, as the US Supreme Court upheld the latest version of his travel ban targeting people from some Muslim-majority countries.
By a 5-4 vote, the court's conservative majority said Trump was within his legal authority as president to issue such a ban.
Trump pounced on the decision as an endorsement of his authority to defend national security and "a tremendous success and victory for the American people."