"By some estimates, as many as one in 100 people have differences or disorders of sex development, such as hormonal conditions, genetic changes or anatomical ambiguities, some of which mean that their genitalia cannot clearly be classified as male or female.
For most of the twentieth century, doctors would often surgically alter an infant’s ambiguous genitals to match whichever sex was easier, and expect the child to adapt. Frequently, they were wrong. A 2004 study tracked 14 genetically male children given female genitalia; 8 ended up identifying as male, and the surgical intervention caused them great distress (W. G. Reiner and J. P. Gearhart N. Engl. J. Med. 350, 333–341; 2004)."
It is inaccurate to claim people have a mental illness solely because they don't fit into your very simplistic categories.