This past week, a federal judge struck down the president's latest immigration order. It's been a chaotic two years on the border as the administration imposed barriers with little consideration of their legality or consequences. The 2017 ban on travelers from Muslim countries was so abrupt it surprised the officers who had to enforce it. Before the midterm elections, President Trump ordered thousands of troops to Texas to stop what he called "an assault" by a caravan of Central Americans. That caravan is now at the border of California.

But the most tumultuous order of all, was this summer's separation of children from their parents, which Mr. Trump had to quickly withdraw. Our investigation has found that the separation of families began far earlier and detained many more children than the administration has admitted.

This is a Department of Homeland Security arrest warrant issued during the child separations last spring. The target of the arrest is a three-year-old named Immers.

Scott Pelley: Tell me about the moment that Immers was taken away from you.

Three-year-old Immers, who had an arrest warrant filed against him after he crossed the southern border with his father CBS News

His father, Ever, told us, "I never thought that they would separate him from me. But an immigration agent said, 'you're going to be separated, your son is going to be taken away and then a judge will decide what will be done with you.'"

Immers and his father crossed the border illegally but presented themselves to the Border Patrol and requested asylum. Ever, the father, says he was shot in the back in Honduras, a country at war with gangs and drug cartels. As asylum applicants, they're permitted by law to stay until their hearing, usually in two or three months. Before, most asylum seekers were released at that point, but under the Trump administration they were arrested and charged with a crime. Because children can't be incarcerated, Immers was sent to a foster family in Michigan.

"I don't know what part of your soul has to be missing to say, 'We'll take an infant from its mother with no provision about how they will ever get back together again.'"

Scott Shuchart: If you're going to separate families in the pursuit of an immigration policy, it was irresponsible to push that on top of a system that wasn't prepared on the backend to allow the families to be reconciled later.

Scott Shuchart was surprised by the new policy even though he worked at Homeland Security headquarters at the Office of Civil Rights and Civil Liberties. He told us the order was so abrupt it bypassed the usual review.

Scott Pelley: If they had come to you, what would your office have said?

Scott Shuchart: We would've had advice on the way that needed to be done, on the recordkeeping that needed to be done. And our advice on that wasn't sought out. And when we tried to provide it, it was ignored.

Scott Pelley: What do you mean by recordkeeping?

Scott Shuchart: Making sure that we knew where everybody was at all times so that they could be put into contact and reunited later. People were removed to other countries without there being good records of what adult went with what child.

Scott Shuchart, who worked in the Department of Homeland Security CBS News

That's what we found in this Homeland Security internal investigation. It says one border station, "made no effort to identify and reunite families prior to [their] removal [from the United States]." The DHS inspector general says the agency was "not fully prepared" and "struggled to provide accurate, complete, reliable data on family separations…" The report found that incompatible computer systems erased data that connected children with their families.

Cecilia Munoz: I don't know what part of your soul has to be missing to say, "We'll take an infant from its mother with no provision about how they will ever get back together again." They might never see each other again.

Cecilia Munoz handled immigration in the Obama administration as the director of the Domestic Policy Council. She says that even though apprehensions at the border have been trending down for a decade, many administrations struggle with the patchwork of U.S. laws that require border security and protection of asylum seekers.

Scott Pelley: You know better than most that there are people watching this interview who are saying, "They shouldn't have come."

Cecilia Munoz: We have a broken immigration system. I've been working on this in this policy area for 30 years; I'll be the first to say we have a broken immigration system. The question is what we do about that. We lack the political will to fix it. And we will continue to create crises, crises of our own making, until we fix it. And some of all that's on us. We live in a democracy. We all know everybody who-- no matter how you feel about immigrants, including the people who don't like immigrants, we all agree this thing is broken.

Scott Pelley: When the Trump administration made the decision to separate children from families, what responsibilities did they take on, in your estimation?

Cecilia Munoz: They issued an order without consulting with the agencies who were responsible for carrying out that order. We take better care of people's effects when we send them to jail than we took care of the children who we took from their parents. And that's because these decisions were clearly made at the top and pushed down to the agencies without thinking through the ramifications and without thinking through the potential harm.

Cecilia Munoz, who handled immigration in the Obama administration as the director of the Domestic Policy Council CBS News

Dr. Pam McPherson: I was having trouble sleeping at night.

Psychiatrist Dr. Pam McPherson and internist Dr. Scott Allen were also caught off guard. They too, work for Homeland Security, inspecting government detention facilities. They were already concerned about the poor quality healthcare for a limited number of children in custody before the new order.

Dr. Scott Allen: There was an episode where children in a mass immunization program were immunized with the wrong dose, adult dose instead of child dose, because the providers at the facility weren't used to working with children and didn't recognize some very common color coding that would denote adult versus pediatric vaccines.

They'd been writing reports of poor pediatric care in federal custody for four years when they heard that thousands more children were going to be cared for by the government, some of them in tent cities.

Dr. Scott Allen: This is what caused us great concern, with the disclosures that this policy was going to be ramped up and rapidly expanded. We understood that that action would create an imminent threat to the harm and safety of children.

Psychiatrist Dr. Pam McPherson and internist Dr. Scott Allen, who investigate government detention facilities for the Department of Homeland Security CBS News

Scott Pelley: Dr. McPherson what were your concerns in the mental health field?

Dr. Pam McPherson: I had concerns about the trauma that the children could experience, about the cumulative traumatic stress that could lead children to have delays in developmental milestones, difficulties with their memory or thinking later, difficulties forming relationships and regulating their emotions.

"We were being asked as a department to do something that violated the civil rights and civil liberties of persons."

Three-year-old Immers, the boy with the arrest warrant, was placed by the government with a foster family in Michigan for 73 days. This was his reunion with his mother.

She's saying, "I'm your mother honey, what is wrong with my son?"

In an interview, Gladys told us, "It felt like he wasn't my son anymore. It felt like a nightmare. Like I was dead."

She says, since detention, Immers has been withdrawn and moody.

"And from that day until today," Gladys said, "It's been very difficult to deal with him."

Dr. Pam McPherson: When a child looks to their parent for comfort and the parent's not there, the child quits looking for comfort. Once the child detaches, they can have lifelong difficulties forming relationships.

Immers' father told us he was separated from his son without notice. After a court hearing he went straight to detention without seeing his son to say goodbye. Homeland Security's inspector general found parents often did not understand "…their children would be separated" [and] they would be "unable to communicate with their children after separation."

Lee Gelernt: It became such a horrific scene that they started telling the parents, "Oh, your child is just going to take a shower, or just going to get some medical treatment," and then the parent would never see the child again.

Lee Gelernt is an attorney with the American Civil Liberties Union. In July, he convinced a federal judge to order the reunification of the children. But when the government realized it lost track of many of the parents, the Trump administration told the court reuniting the families was the ACLU's problem.

Lee Gelernt: The government took these children away from their parents, and then deported hundreds and hundreds of the parents without the children. The judge said, "These parents need to be with their children." And the government said, "Well, if you wanna find the parents, we don't know where they are. Let the ACLU look for them."

Lee Gelernt, an attorney with the American Civil Liberties Union CBS News

This is the Homeland Security order to arrest and detain all adults who crossed illegally to seek asylum. The copy released to the public was censored by the administration. But we've obtained what the White House didn't want the public to see. The document reveals that child separation began nine months earlier than the administration acknowledged. There was a pilot program in the busy "El Paso sector" from "July to November 2017". We don't know how many children were taken in those five months. The censored part of the memo explains a reason for the policy -- deterrence -- as it "will have the greatest impact on current flows" [of immigrants.]

But Cecilia Munoz says the Obama administration found that deterrent messages failed to turn back immigrants.

Cecilia Munoz: And the reason for that is, if your child was told today by the gangs, "Your life is at risk unless you start running drugs for us." You're thinking much more about their safety today and tomorrow than you're thinking about, "What's going to happen once we get to our destination?"

Jeff Sessions: We are not going to let the country be overwhelmed.

Security was the stated reason for the policy change. One top White House official called immigration an existential threat to America. But Homeland Security's inspector general found the chaotic implementation of the policy undermined law enforcement. The report says, "instead of patrolling and securing the border, officers had to supervise and take care of children." And those officers weren't prepared for their new role, according to Scott Shuchart, who recently left Homeland Security.

Scott Shuchart: I can't believe that we sent Border Patrol agents out to take people's children from them without training on the appropriate and humane way to do that. It was just the machine moving forward with enforcement without an appropriate consideration of how it affected all of the people who were involved.

Scott Pelley: You quit your job at Homeland Security. I wonder why.

Scott Shuchart: I had taken an oath to uphold the Constitution. We were being asked as a department to do something that violated the civil rights and civil liberties of persons. And my office was being frozen out of that process. There wasn't a job responsibly for me to do.

Immers, who was taken from his family for 73 days, was reunited with his parents after the court order. An immigration judge ruled that Immers' father does have a well-founded fear of returning to Honduras. His asylum claim is being considered.

President Trump: I didn't like the sight or feeling of families being separated.

No senior official would speak to us for this story but President Trump ended his separation policy after 11 weeks. The White House says more than 2,600 children were detained. But reports from various agencies show at least 5,000 children have been held since Mr. Trump's inauguration. The White House says only 25 remain to be reunited with their families, but given the bungled recordkeeping, and no public accounting of the mysterious El Paso pilot program, there may never be an accurate count of how many children were taken from their parents.

Produced by Oriana Zill de Granados and Michael Rey. Associate producer, Emily Gordon.