FOR LURKERS:
"Intersex" is an old-fashioned and othering term. People living with DSDs are all either male or female - all DSDs are sex-specific. In the past, before sophisticated sexing techniques, a small percentage of the approximately 0.018% of babies who are born with DSDs were incorrectly thought to be the other sex because of the appearance of what seemed to be their genitals. In such cases, parents were advised to socialise their child as a boy or a girl depending on that appearance. Sometimes it became clear later on that the sex of the child had been wrongly guessed. Their sex had not changed in the meantime, it just became more obvious. (The condition that Caster Semenya has has a genetic component and is known locally as "penis at 12" because the penis only develops properly at puberty.) Some people elect to continue to present to society as the same sex in which they have been socialised, even if they are in fact the opposite sex. Those are the only cases where sex was /isassigned. Nobody assigns gender to any child.
We know the causes of DSDs. They include: nonstandard karyotypes (chromosome combinations), displacement of the SRY gene, insensitivity to certain enzymes. A karyotype is not a sex. Your chromosomes are evidence of your sex - as much as the primary and secondary sex characteristics, visual, smell and sound cues which enable humans to sex each other with close to 100% accuracy even when steps are taken to alter outward appearance.
Sex is binary and cannot be changed. It has never happened in mammals. That evolutionary possibility was closed off millions of years ago, before mammals evolved. Sexual reproduction means large gamete + small gamete = zygote -> foetus -> baby, all being well. Your sex is dictated by the SRY gene (almost always located on the Y chromosome) and it is the biological role which your phenotype plays in sexual reproduction (whether or not you choose to, or can, reproduce). The sex of a person decides which phenotype they have, and which hormones and enzymes are released in the womb and throughout their life. The hormones etc determine which sex organs will develop out of the undifferentiated tissue in a foetus and which will be suppressed. In other words, you develop a vagina because you are female, it's not that having a vagina confers femaleness on you. Having a vagina is excellent evidence of femaleness, not femaleness itself. Similarly, a wedding ring and a marriage certificate prove you are married, but if you lose your ring or burn your certificate, you are still married. It's just harder to prove that you are married. Stealing a wedding ring or forging a certificate will not change your marital status. A double mastectomy or a penile inversion make no difference to which sex you are - the breasts and penis are evidence of your sex, not your sex itself. Also note that though it's possible to remove a sex organ or characteristic, you cannot swap in a functioning version of an opposite sex organ or characteristic - because the phenotype is not set up for it. Vaginoplasty and phalloplasty do not create vaginas and penises.
There are only two sexes because sexual reproduction requires two types of gametes - small gametes and large gametes. The phenotype which is set up to produce large gametes is referred to as female and the other one is referred to as male. The development pathways of each phenotype are parallel, ie they never cross over or meet. The phenotypes resulting from these pathways may be imperfectly realised, but they are always one or the other - male or female -
because there are only two types of gamete.