The family of toddler Mohammad Musa had kept the boy in hiding after authorities pressed charges accusing him of trying to kill police officers after a neighbourhood brawl in Pakistan's eastern city of Lahore.

Judge Rafaqat Ali Qamar dropped the case during a hearing in which police announced they would no longer pursue the charges, defence lawyer Irfan Tarar said.

"The father of toddler produced him before the judge today," Mr Tarar said. "The boy was in the arms of his father when police submitted a report, stating they have dropped the charge against the boy."

The judge also reprimanded police in court, demanding a written explanation about why officers did not properly investigate the case, Mr Tarar said.

The case stems from an incident on January 31, when power company officials went into the boy's neighbourhood to disconnect illegal power lines allowing people to get electricity to their homes without paying for it.

Police said neighbours threw stones at energy company officials and their officers. The boy's grandfather, Malik Muhammed Yaseen, said local women attacked the police with batons only after officers mistreated residents.

That altercation sparked police to open an attempted murder investigation into 30 people in the neighborhood, including the father of the toddler and his son, police officer Atif Zulfiqar said earlier this week.

Mr Yaseen said police came to his house multiple times looking for the boy. He said the family told police he was less than a year old, but officers demanded they take him to court. The boy received bail and wept as police took his fingerprints.

The case highlighted the country's dysfunctional criminal justice system, where even children are not immune.

Pakistan's police, widely criticized as improperly trained and ill-equipped, is routinely accused of torturing suspects and extorting people for bribes. Flaws in the country's legal system and poor police investigations often see criminals and terrorists released, while militants routinely target officers in their attacks.

Mr Tarar said the toddler's whole family was very happy.

"After today's court order, the nine-month-old boy is free to live anywhere," he said. "This case is an eye opener, and we hope and expect that police will avoid any repeat of such mistakes."