Images of Liam Conejo Ramos, with a bunny hat and Spiderman backpack being surrounded by US Immigration and Customs Enforcement Officers, sparked even more outcry about President Donald Trump's administration's immigration crackdown in Minnesota.
It also led to a protest at the family detention centre and a visit by two Texas Democratic members of Congress.
US District Judge Fred Biery, who was appointed by former Democratic President Bill Clinton, said in his ruling "the case has its genesis in the ill-conceived and incompetently-implemented government pursuit of daily deportation quotas, apparently even if it requires traumatising children".
A judge had previously ruled that the boy and his father, Adrian Conejo Arias, could not be removed from the US, at least for now.
Neighbours and school officials say that federal immigration officers in Minnesota used the preschooler as "bait" by telling him to knock on the door to his house so that his mother would answer.
The Department of Homeland Security has called that description of events an "abject lie". It said the father fled on foot and left the boy in a running vehicle in their driveway.
During the January 28 visit with Democratic members of Congress Joaquin Castro and Jasmine Crockett, the boy slept in the arms of his father, who said Liam was frequently tired and not eating well at the detention facility housing about 1100 people, according to Castro.
Detained families report poor conditions like worms in food, fighting for clean water and poor medical care at the detention centre since its reopening last year.
In December, a report filed by ICE acknowledged they held about 400 children longer than the recommended limit of 20 days.