The young refugee, believed to be aged 12, said his trip had been "planned and paid for" by his mother, who thought he would have a "better and safer" life in Britain.
He was found unaccompanied at the airport and temporarily placed with a foster carer by Hillingdon Council social services staff.
But social services bosses at Hillingdon Council asked High Court judge, Mrs Justice Theis, to make a decision about the boy's future.
Details of the case emerged after the ruling during a family court hearing in London, where the judge decided the boy could not be named.
Mrs Justice Theis told the court: "There is some uncertainty as to precisely how he arrived at Heathrow Airport, and what methods of transport he had between Afghanistan and the United Kingdom.
"The whereabouts of his mother are unknown and it would be impossible to return (him) to her care in Afghanistan at this time.
She said it was "right" council bosses should be able to exercise parental responsibility.
Mrs Justice Theis ruled the boy should go into council care in England so the boys' welfare interests could best be met.
Home Office officials will have to make a decision about his immigration status in the future.
Keep up to date with the latest news in west London via the free getwestlondon app.
You can set up your app to see all the latest news and events from your area, plus receive push notifications for breaking news.