Sex change by gene switch. Apparently there is a gene that sometimes turns on when it shouldn't or fails to when it should that determines a person's gender. By "shouldn't" and "should" I mean that this gene is what accounts for people with XX chromosomes developing testicles and people with XY chromosomes developing ovaries. It essentially causes them to become the opposite sex of their chromosomal designation. While not incredibly common it could affect as many as 1 in every 20,000 people.
An interesting aspect of the brief article is where the authors suggest that with further study of this gene (Sox9) "scientists may determine ways to reassign gender later in life". In other words, actual gender reassignment, not just cosmetic.