Hallo,
to get married mostly takes much time. You must have a set of personal documents from your country, like a passport, a birth certificate and a confirmation that you were not married before (or divorce certificate). For a lot of countries the Standesamt would claim that the documents must be legalised in the German embassy of your country, which costs much money and takes much time.
So to make the custody of a child is a quicker way which at least gives you a reason for a Duldung on a humanitarian reason. On the other side it doesn't make you fully safe, especially before the baby is born. But as Meike wrote, people normally can get a Duldung after rejection even without any special reason, just because a deportation is mostly not a quick thing.
The child is also not a full guarantee that the Ausländerbehörde lets you stay in Germany without leaving and making a family reunion. In this case it is much more better to be married. It is not so easy to make a family reunion to a child if the child has a parent with a custody (the mother) is in Germany.