A federal judge has ordered the immediate reunification of an asylum-seeking father and his two-year old son, who have been separated for nearly six months under Donald Trump’s family separation policy.

“It’s the most cruel of all cruelties to separate a child from his father when there is no basis,” said New York southern district judge Alvin Hellerstein at a hearing on Monday afternoon.

The father, known as Mr C, was released from detention last week after crossing the border around 30 April. His son, who has spent a quarter of his life in US government custody, was being held in the Bronx, New York City.

Earlier this year, the Trump administration separated more than 2,600 children from their parents at the border under its zero-tolerance policy, which made family separations possible until Trump signed an executive order ending that practice in June. Several lawsuits ordering reunifications are being fought across the US.

Mr C said the pair fled Honduras because the gang MS-13 threatened to kill him and his son, and had already killed members of his extended family. He crossed the border with a notarized letter from the boy’s mother approving her son’s travel.

US justice department attorney, Brandon Waterman, said the government needed to complete a statutory process to reunite the father and son and suggested that the government had kept them separated because of a 2010 misdemeanor charge Mr C incurred in Louisiana for aggravated assault.

A mother migrating from Honduras with her child surrenders to US border patrol agents after illegally crossing the border, near McAllen, Texas, on 25 June. Photograph: David J. Phillip/AP

Hellerstein was dismissive of these explanations and throughout the hearing emphasized the government’s defense failed to prove the father would be an unfit guardian for his son or that the mother opposed her son being in the custody of his father.

The Center for Constitutional Rights took up Mr C’s case and he was freed from detention on Wednesday. On Thursday, he filed paperwork to be reunited with his son. “Friday, the child should’ve been restored to his parent,” said Hellerstein.

Hellerstein said in court he would sign an order for reunification that day and did so on Monday afternoon.

Outside the courtroom after the hearing, Mr C smiled while speaking through a translator. “I am just going to feel so much happiness and for me, I feel like the pain is already going away,” he said.

Mr C said he cried when he saw his son briefly on Thursday after being released from detention. “He’s a beautiful boy, he’s grown a lot, he’s saying more words,” he said.

Mr C said they played with toys together and took pictures together to send the boy’s mother, who is still in Honduras. “I was so overcome with happiness my heart broke more,” he said.

Once the father and son are reunited, they plan to live with Mr C’s sister in Texas.

The child has been in the custody of the US health department since early May.

During the hearing, it emerged that the child’s court-appointed guardian and the government had different explanations for where the child spent his days. Mr C’s attorneys said the guardian had told them the child was in a health department child facility during the day and with a foster family on nights and weekends. The government said the child was always with the foster family.

Judge Hellerstein’s questions seeking to clarify this and other matters underscored the complicated nature of Trump’s family separation policy.

In a damning report released this month, the homeland security department’s office of inspector general (OIG) said the government was not prepared to implement the zero-tolerance policy that made family separation policy or to respond to its impact.

The Trump administration, however, is looking to revive family separation, according to the Washington Post, which said last week that the US government is weighing alternatives including a “binary choice” plan that would give parents option to separate voluntarily or be detained together for years.