This practice has been going on for decades - if a child's parents are criminally prosecuted and held in federal prison awaiting trial, then family separation must occur as a consequence as children may not be held in federal prison. In addition, due to the 1997 Flores Settlement, children may not be held in an immigration detention center for longer than 20 days. As a result, if a child's parents are held in a detention center for longer than this period, the child is required to be separated from their parents.
The reason this became a particular issue in 2018 is thanks to the implementation of the Attorney General's 'zero tolerance' policy, announced in April of that year:
Accordingly, I direct each United States Attorney's Office along the
Southwest Border to the extent practicable, and in consultation with
DHS- to adopt immediately a zero-tolerance policy for all offenses
referred for prosecution under section 1325(a). This zero-tolerance
policy shall supersede any existing policies. If adopting such a
policy requires additional resources, each office shall identify and
request such additional resources.
This had been a Trump campaign promise on immigration - from a rally in August 2016:
Number two, we are going to end catch and release. We catch them, oh
go ahead. We catch them, go ahead.
Under my administration, anyone who illegally crosses the border will
be detained until they are removed out of our country and back to the
country from which they came.
[...]
Number three. Number three, this is the one, I think it's so great.
It's hard to believe, people don't even talk about it. Zero tolerance
for criminal aliens. Zero. Zero.
Zero. They don't come in here. They don't come in here.
Before this policy, suspected illegal immigrants and asylum seekers were allowed into the US while waiting for their cases to be processed. This was due to cases predominantly being handled with civil proceedings in special immigration courts which doesn't require incarceration before trial. According to the NYT, "the majority of those taken to federal court for criminal prosecution either had been apprehended at least twice before, or had committed a serious crime."
There could be a significant amount of time before a case is heard in one of these immigration courts. According to NOLO:
The scheduling of your first hearing will depend on how busy the court
is. In recent years, most immigration courts have been extremely
busy—there are a lot of people in removal proceedings and not enough
judges to hear their cases. Depending on what court you will go to and
how busy that court is, you might wait a few months or a few years.
Consequently, children could stay with their parents during this time. As a result of the implementation of the Attorney General's policy, instead of being handled in an immigration court, all suspected illegal border crossings were meant to be criminally prosecuted. This lead to more suspected illegal immigrants being imprisoned awaiting trial, or subject to detention, and as a result, an increase in family separations occurred.
In response to building public pressure, for example from former First Lady Laura Bush, President Trump issued an executive order entitled Affording Congress an Opportunity to Address Family Separation on June 20th. According to NYT:
The order states that it is now the policy of the Trump administration
to keep families together. It appears to envision a system in which
families will be housed together in ad hoc detention centers,
including on military bases, that the administration hopes a court
will approve. It calls for many agencies — including the Pentagon — to
make available “existing facilities,” or to construct them, for the
Department of Homeland Security to use “for the housing and care of
alien families.”
On June 26th, U.S. Customs and Border Protection Commissioner Kevin McAleenan told reporters that, as a result of Trump's executive order, migrant parents crossing in from Mexico illegally would no longer be referred for prosecution. On the same day, a federal judge issued a nationwide injunction which halted the process.
Judge Dana M. Sabraw of the Federal District Court in San Diego said
children under 5 must be reunited with their parents within 14 days,
and he ordered that all children must be allowed to talk to their
parents within 10 days.
“The unfortunate reality is that under the present system, migrant
children are not accounted for with the same efficiency and accuracy
as property,” the judge wrote.
[...]
In his order, Judge Sabraw said that children may be separated at the border only if the adults with them present an immediate danger to the children.
He also said that adults may not be deported from the United States without their children.
In later cases over the next two months, Judge Sabraw suspended family deportations for a week to allow reunifications to take place, and then ruled that the burden of reuniting separated families fell on the government.
In October 2018, the ACLU reported on the efforts undertaken to reunite children with their parents - 2,654 children were initially determined to have been possibly separated from their parents, and of these, there remained 120 children who were separated from their parents, were in ORR care as of Oct. 15, and who have not decided to waive reunification.
Although the court orders, combined with Trump's executive order, ended the majority of family separation, they did not end it completely. The same federal judge, Judge Sabraw, sided with the administration in January 2020, stating that the government "acted within its authority when it separated more than 900 children from their parents at the border after determining the parents to be unfit or dangerous."
In conclusion then, yes, the practice of separating children from their parents when they enter federal prison or detention centers has been going on for decades, but before the Trump administration's zero-tolerance policy on illegal immigration led to a vast increase in migrant detention, this was not so much of an issue at the border.
The zero-tolerance policy on pursuing criminal prosecutions took place predominantly from April 2018 to June 2018, when it was mostly ended as a result of a nationwide injunction and an executive order signed by the President. However, family separation still occurs when parents are 'considered unfit or dangerous, or in other limited circumstances like criminal history, communicable diseases and doubts about parentage'. This practice has been tested in court, where it was found that there was 'no evidence to conclude the government was abusing its power'.