After, not before, you get to the hospital, I always say.
But seriously, Robert Martin, the famous primatologist, has an interesting piece in Psychology Today exploring this question. Go read it. I’ve got a few thoughts spurred by this research I’ll list briefly here.
First, it seems that wild primates give birth during their daily down-time, the period of time that they are generally inactive. Dirunal primates do so more at night, nocturnal primates do so more during the day. Various reasons have been proposed. I’ve not read the primary literature on this, but in my ignorance I wanted to propose a possible (maybe additional, maybe already covered) idea. It has been suggested that this is to avoid predation. It could also be the case that the down time itself happens when it does for the same reason, to avoid predation while resting. Consider just diurnal primates for a moment. Resting is probably a time that primates are more likely to be preyed on for one specific reason: they don’t have as many eyes scanning from as many angled over a large area. This would apply only to social primates, especially those that sometimes forage in multi-species groups. So, resting times would be times of lower vigilance, so those times are ideally placed during times when predators are less active. Nocturnal/crepuscular primates are least active during the part of the day that primates are less active, and diurnal primates that start to hunt in the morning may have fed by them.
I quickly add that this is a counterintuitive idea (the part about resting being placed during the low-risk time of the day). The assumption is usually that resting means you are quiet and hard to find, so less susceptible to predation. But the predators already know where the primates are, and can find them. Being more active may make primates more visible to other primates including human primatologists (arboreal monkeys can be hard to spot when they are just sitting there … usually you spot them when branches are swaying and calls are sounding). So it would be a tradeoff between increased vigilance associated with foraging (because you are out and about and observant), decreased vigilance associated with foraging (because you are busy stuffing your face with goodies), increase vigilance because you are resting (because you can sit there and look around without distraction) and decreased vigilance because you are resting (because you are zoning out and if you are hiding among thick vegetation have less of a view). Being a primate is complicated.
Like other diurnal primates, humans seem to give birth more at night. This is perhaps the baseline starting point for humans further developing a nocturnal active phase to their activities, which for a long time has been thought an important part of evolution. We social beings invent fire and this produces a sitting around the fire thing where we use language to do stuff. Sex too. Diurnal primates not only feed and move about during the day, but also have sex during the day, and in the open. The human pattern is to generally have sex at night, and more privately. This is what happens, perhaps, when you take a monogamous bird/gibbon-like mating system and deploy it in a highly social primate.
So the night time behavioral niche includes a number of activities, including sex, gossip, and popping out babies. All closely related things.