LOS ANGELES—A federal judge has ruled that the U.S. Department of Justice’s current system of detaining children with their mothers after they’ve crossed the U.S.-Mexico border violates an 18-year-old court settlement.

The decision Friday by U.S. District Judge Dolly Gee in California is a victory for the immigrant-rights lawyers who brought the case, but its immediate implications for detainees weren't yet clear. The ruling upholds a tentative decision Judge Gee made in April, and comes a week after the two sides told her...