There are a great many variables to be considered here.
Many Western nations do have mother and baby jail units, and these are not just for those who give birth whilst inp rison but also for those very recent births prior to incarceration.
Social services would look at the whole picture, is there a father or any other close relative to the child who could take custody.
Sadly there are a significant number of babies born who are already addicted to hard drugs and this may require a long period of hospitalisation for the child.
If the jail term is short, which is very often the case for women, then the baby may be allowed to remain with the mother.
It has been the case that some women have made sure they would be pregnant between arraignment and the actual trial and sentencing in the hope of obtaining leniency from the courts, or maybe an increased chance of parole when sentenced.
Here are a few things for you to read.
http://society.guardian.co.uk/crimeandpunishment/story/0,8150,527116,00.html
http://news.bbc.co.uk/hi/english/uk/newsid_387000/387161.stm
One very serious problem for the welfare of the child is that a very large number of prisoners leave jail with very little, which would be hard enough for a lone adult, but for a mother and child it is an unenviable position to be in.
Women are generally lower category offenders than men but there are cases where very serious offences have been committed and appropriate jail terms are handed down.
These are currently rare but it is a growing problem.
Social service agencies take such circumstances into account, after all, if the only motivation for having a child is the hope of a lesser jail term rather than the welfare of the child itself it may well be in the best interest of the child to be adopted, there is usually no shortage of prospective parents for a baby.
It is not a simple issue.