Not really sure what point you're trying to make with your opening paragraph, but a person's gender is determined by their chromosomes long before birth. XY - male. XX - female.
Actually, this is emphatically not true. We have
Androgen insensitivity disorder: (as FireDragon76 said) where an XY individual can end up with a female phenotype (physical appearance).
Swyer syndrome: Like Androgen insensitivity disorder in that an individual with an XY genotype ends up with a female phenotype.
Klinefelter syndrome: An individual has a XXY genotype had as a male phenotype.
Non-Klinefelter XXY: Usually the XXY individual develops a male phenotype, but can develop a female phenotype if the SRY gene is inactive.
Turner Syndrome: An individual has a XO genotype and female phenotype.
XYY Males: As the name indicates, a male has a XYY genotype.
XXX Females: As the name suggests, a male as a XXX genotype.
XO/XY Mosaicism: The individual only has a Y chromosome in some cells; the individual can end up with either phenotypicaly male or phenotypically female depending on the individual.
XX male syndrome: This is when the sex determining region of the Y chromosome crosses over with the X chromosome during meiosis, resulting in an individual with an XX genotype and a male phenotype.
This is only a small sampling of genetic syndromes that can muck with sex determination, and it's leaving out the syndromes or aspects of the syndromes that can lead to ambiguous genitalia.
When this topic comes up people are often inclined to act as if sex determination is something that is easy and simple biologically (XX = female, XY = male) and that it's only those silly transgender people who are ignoring the clarity of biology, but it simple isn't the case that sex determination is easy even within biology.