On what basis is a soul born as male or female?
We can get an answer from the embryological point of view as found in an Upanishad called the Garbha Upanishad (which is linked to the Krishna Yajur Veda).
In the fourth month, belly and hip are formed; in the fifth month, the backbone is formed; in the sixth month, nose, eyes and ears are formed.
In the seventh month, [the embryo] comes to have the jīva (conscious self), and in the eighth month, it becomes complete in every sense.
If the father’s seed is more potent, it becomes male; if the mother’s seed is stronger, it becomes female. If the seeds are equal, it becomes an intersexual (napu÷saka, neither male, nor female).
If [at the time of impregnation] the parents are agitated, the child will be blind, crippled, hunch-backed or stunted. If the vital air moves around, the seed enters in two parts, resulting
Additionally this Upanishad also states that a child can remember his past life in the 9th month.
Whatever is consumed or drunk by the mother passes through the nerves and vessels to the child, becoming the source of his satisfaction. During the ninth month, all outer signs attain completeness. And he is reminded of his previous birth, and recounts the good and bad deeds committed.
He thinks: I have seen thousands of wombs, eaten several kinds of food and sucked many breasts. Born and dead again and again, I am immersed in grief but see no remedy. Thinking of my good and bad deeds, I am suffering alone, although the bodies that enjoyed the fruits are gone.
But, it forgets everything, as soon as it comes out of the mother's womb, due to the influence of the Sutika Vayu and that of Mahamaya.
I have similar verses from Tantras as well, but right now can not post them, because the books are not with me right now.
Source- The Garbhopanishad.. You can get the Sanskrit verses from this PDF but i am not able to paste them here (getting some weird characters).
Note: “The question: On what basis is a soul born as male or female?” is licensed by Stack Exchange Inc (https://hinduism.stackexchange.com/); user contributions licensed under CC BY-SA.