We know famously that upon Leah becoming pregnant with her seventh child, she realized that if she were to give birth to a boy it would mean that out of the twelve tribes, she would have given birth to seven, the two maidservants Bilha and Zilpa each had two, and this would mean that her sister Rochel would be deemed inferior to even their handmaids in the formulation of the twelve tribe as she would be responsible for giving birth to only one of the tribes.
Such was her distress for her sister that she davened that the gender of the baby be changed. Rashi on the pasuk in Bereishis 30:21 tell us:
דינה. פֵּרְשׁוּ רַבּוֹתֵינוּ שֶׁדָּנָה לֵאָה דִּין בְּעַצְמָהּ, אִם זֶה זָכָר לֹא תְהֵא רָחֵל אֲחוֹתִי כְּאַחַת הַשְּׁפָחוֹת, וְהִתְפַּלְּלָה עָלָיו וְנֶהְפַּךְ לִנְקֵבָה (ברכות ס')
DINAH (Judgment) — Our Rabbis explained, that Leah set herself up as judge (דנה) against herself saying: “If this be a son, my sister Rachel cannot be even the equal of any of the handmaids”. She, therefore, offered prayer regarding it, and its sex was changed (Berachos 60a).
The Targum Yonasan 30:21 goes one step further further and says that the actual embryos were switched. So Yosef was moved into the womb of Rochel, and Dina into the womb of Leah.
In keeping with this idea, I once heard a vort that as a result of this switch, despite being born as the individuals they were, they maintained a semblance of what their initial gender would have been, i.e. Yosef carried some female traits which accounts for his preoccupation with his hair etc. (see Bereishis Rabba 84:7), whilst Dina maintained some male leanings which is why she was emboldened to go out on her own (Bereishis 34:1).
Does anyone know the source for such an idea?