Latvian Elita Amantova, 39, was living off berries and bread left out for the birds in Tooting, south-west London, before she gave birth to the child in 2012, a court heard.
The tragic death was discovered after a fox dug up the baby on Tooting Common and dumped body parts in a nearby tractor yard.
At a hearing at the Old Bailey, Amantova admitted infanticide and was sentenced to a hospital order.
The court heard she had been diagnosed with a schizophrenia-type mental condition in Latvia in her 30s but it was exacerbated by childbirth.
Outlining the facts of the case, prosecutor Zoe Johnson QC told how the defendant had an “appalling experience” after she came to the UK around 2008.
After losing her job, she found herself in the company of organised criminals in Norfolk who set her to work as a prostitute.
In August 2012, she fled to London where she was found sleeping rough in a burial ground off Garratt Lane in Tooting.
The court heard that by then she was heavily pregnant, living off berries and bread left out for birds, sleeping on grave stones and wearing a blonde wig.
A member of the public, Verity Verster, became concerned about her condition and alerted authorities, Ms Johnson said.
As a result, a police constable tried to persuade her to go into suitable accommodation but she refused help and officers decided there was nothing more they could do.
Ms Johnson went on: “On September 10 2012 a worker found a baby’s leg and foot on the ground at the tractor yard at Doctor Johnson Avenue next to Tooting Common.
“The leg was infested with maggots. In a search, another limb was found, the thigh and calf had been eaten through exposing bone.
“Later, a fox expert was called to the yard and discovered a fox entrance.”
During an interview in April 2013, Amantvova admitted to a doctor that the child had been alive and she was charged with murder.
However, at yesterday’s hearing the prosecution accepted her plea of not guilty to murder but guilty to infanticide.