One would think that this should be directed to an "Ask the Doctor" website, as opposed to "Ask the Rabbi"... But indeed, the Torah encompasses all subjects—and this is no exception.
Our souls existed long before we were born. They lived in a pristine spiritual world and were one with G‑d in every way. Their thinking was not limited to that of a human mind; their seeing was not limited to that of a human eye.
Life in our world is very different. And so, as a baby forms physically, its soul must undergo a "spiritual transformation" before entering this physical world.
Using Kabbalistic terminology, the soul originates in the spiritual world of Atzilut ("Emanation"). That world contains ten sefirot, or levels, and the soul gradually descends throughout these levels until it reaches the last level, Malchut—at which point the baby is born.
The soul's nine-step journey manifests itself physically in a nine-month pregnancy.
Click here if you'd like to gain a basic understanding of the sefirot.
Yours truly,
Rabbi Yisroel Cotlar
Re: We are told that pregnancy didn't always last nine months. Eve gave birth to Cain and Abel on the same day that she was created. And the Midrash tells us that quicker pregnancies lasted up until the time of the flood (Midrash Rabbah Genesis 36) But due to the lower state of our world, it now takes nine months for a soul to be ready to enter a body.
But there have been some exceptions—most notably, Moses. He was called Moses because he was "drawn from the water." In the teachings of Kabbalah, this is explained to mean that his soul was taken directly from the concealed, deeper levels of Atzilut. And this manifested itself in a physical manner, as he was born after only six months of pregnancy (Rashi.)
Can we say the same with certainty for every premature baby? Not at all. Such matters are beyond the understanding of our limited minds.
However, we are told that in the times of Moshiach, pregnancy will indeed go back to being a quicker (and painless) process. (See tractate Shabbat 30b.)