If the children are younger than 5, they must be reunified within 14 days of the order, issued Tuesday.
U.S. District Judge Dana Sabraw in San Diego issued the order in a lawsuit by the American Civil Liberties Union. The lawsuit involves a 7-year-old girl who was separated from her Congolese mother and a 14-year-old boy who was separated from his Brazilian mother.
More than 2,000 children have been separated from their parents in recent weeks and placed in government-contracted shelters. President Donald Trump last week issued an executive order to stop the separation of families and said parents and children will instead be detained together.