Being trans happens because sexual differentiation of genitals occurs earlier and independently of the development of the brain, and so in rare cases these two processes can be influenced differently.
An embryo develops male sex characteristics in the presence of androgens in utero within the first trimester. During the second trimester, those same androgens which drive the development of male characteristics can no longer be present, leading to the fetal brain developing in a more feminine...