Michelle Barnes, 33, from Cumbria, was serving a two-year sentence for drug offences at Low Newton Prison, Durham, when she died in December.
The inquest heard that Ms Barnes had hoped to keep the baby with her.
However, Low Newton has no mother and baby unit, and she was unable to get a transfer to a prison which does.
Ms Barnes - who found out she was pregnant while serving her sentence - had a history of mental health problems and self harming, the inquest jury was told.
Cumbria County Council had begun care proceedings as it had "concerns" about her as a mother.
Her solicitor, Victoria Rowson, said: "Her intention was to be a good mother to her child".
However, an interim care order was made after the baby was born in hospital.
Social worker, Sara Driscoll, said:  "It was not a decision taken lightly at all.
"We believed there was no safe decision for the child, other than removing the child from birth.
"There was one occasion during one of my visits that she said 'If you take the baby, I will go too'.
"I passed that on to her mental health worker."
She agreed with Durham Coroner Andrew Tweddle's suggestion that this was something said "in the heat of the moment".
Earlier, Alan Richer, the most senior governor at Low Newton said the prison experienced 20 to 35 self-harm incidents a month, and it appeared to be a "coping mechanism" for some of the women prisoners.
He said there were around 200 babies born to inmates every year in the UK, and only five prisons which have mother and baby units, after one unit closed due to flooding.
The hearing, at Crook Civic Centre, continues.
An inmate found hanging in her prison cell days after giving birth, told a social worker "if you take my baby I go too", an inquest has heard.