People of ambiguous sex have lived throughout history. Medical, scientific, and social attitudes towards intersexed individuals have varied. Hippocratic writings describe sex as existing along a continuum with female and male at two extremes and hermaphroditism in between. Aristotle’s writings defined hermaphrodites as people of one sex who possessed some extra parts usual found in people of the other sex.
Before surgery became routine, people with ambiguous genitalia were managed by attempting to define their "true" sex so that they could live concordantly. It was commonly believed that there were only two sexes and that despite some confusion, the truth could be revealed about every person.
"Sophie had testicles and a penis; she was surely a man; she was therefore not really married because no marriage between two men was a true or legal marriage. She -- or rather he -- should have her civil status formally changed to male, her marriage officially annulled, and should start acting her "true" sex." 
Intersexuality has been a dilemma. There are case reports of people who were discovered by doctors to be living their lives as the "wrong" sex, cases of disputed sex that came to medical attention when married couples could not have intercourse or conceive a child and women who presented in early adulthood with primary amenorrhea. These people were usually forced to change their status and live according to their "true" sex and couples had to have their marriages annulled. The distress resulting from having to change sex merely because a doctor decided it should be so is unimaginable. However, physicians at the time were trying to maintain social order and correct what they thought had been an incorrect sex assignment at birth.
The "social disorder which resulted from misdiagnosed sex ran so deep that it extended well beyond the immediate problem of same-sex relations and scandalous seductions. It seemed that a suppressed true sex would manifest itself in all sorts of socially disruptive behavior." "If they let a potentially mistaken sex go, they might allow an "error of sex" to continue, ultimately engendering wrongful occupations, scandalous unions, and broken lives." 
The guidelines for determining true sex have changed many times. External genitalia were often used as a sign of "true" sex. Males were considered to have a penis that was susceptible to erection and ejaculation and a scrotum that contained testes. Females had a clitoris, vagina, and labia. These determinants seem straight forward enough. However, confusion could arise if the phallus was a bit small for a penis but too large for a clitoris or if the scrotum was divided into labia that contained testicles. Indeed, even today, the size of the sexual organ is enough to cause concern about sex assignment.
From approximately 1870 to 1915 there was a growing trend of defining true sex by the gonads. The gonadal definition of sex allowed the assignment of one true sex to the majority of individuals, this comforted the scientific and medical community. From this point on, a true hermaphrodite would have to, by definition, have both testicular and ovarian tissue. Thus, true hermaphroditism was made exceedingly rare. As long as each person had one true sex, aberrant behaviors and sexual practices could be identified, proper gender roles and rights could be assigned to most persons, and, social order could be maintained.
The gonadal definition of sex followed the growing importance in medicine of using histology as a marker of disease. At this time, it also became known that the gonads were the earliest embryologic determinants of sex. It was not always easy to use gonads to determine sex in a live person as they could not always be located and, even if they could be, one could not always be sure whether one was palpating an ovary or testis.
Not everyone believed that the assignment of sex was as straightforward as simply locating and identifying the gonads. At a meeting of the British Gyneacological Society in England in 1888, where a case of ambiguous sex was presented, physicians were still debating whether a mixture of characteristics determined sex. Some believed that the genitalia could not be relied upon to determine cases of ambiguous sex because their very ambiguity was the root of the problem. Others pointed out that secondary sex characteristics could not be trusted because it was possible for women to have facial hair, for example, and still be considered women in every other way. Although the physicians still believed that each person could only be male or female, they accepted that there could be multiple factors involved in defining sex. They concluded that, if gonads were the markers of true sex, then their presence would become apparent somehow and that it was the physician’s role to evaluate all the signs that would allow for proper assignment of sex.
Sex, gender, and sexual preference were, until recently, indistinguishable terms. Thus, not only physical attributes but also behaviors could be used to assign sex. It was assumed that true men have masculine behaviors and are attracted to women. If a person had ovaries they were a true female and would therefore be attracted to men, even if she had been mistakenly raised as a male. Thus, cases of seemingly opposite sex couples were deemed perverse. Conversely, the sex of a person could be brought into doubt if she or he was sexually attracted to people of the same sex.
The problem with the gonadal definition of sex can also be demonstrated by considering people with androgen insensitivity. Androgen insensitivity results in individuals who have a 46XY karyotype being phenotypically female. However, these individuals have undescended testes and, according to the gonadal definition of sex, would be forced to live their lives as males even if all their other attributes were female. There are reported cases of physicians during this period overlooking true gonadal sex in very female patients and allowing "unnatural" sex assignment to continue. Sometimes, the physician would remove testicles so that the patient could continue life undisturbed as a female. This measure may have caused less distress for the individual but was considered by some to be damaging to the society because it allowed "unnatural" unions between people of the same sex.
The surgical treatment of infants with genital ambiguity began in the late 1950s and became standard practice in the 1970s. John Money, a psychologist at John Hopkin’s Hospital, was a leading expert in this area    . He and his colleagues believed that gender was defined by upbringing and by the external genitalia. Infants were considered to be gender-neutral until approximately two years of age. Therefore, as long as the upbringing and the external genitalia were matching, they believed that a child could be raised as either female or male   . Evidence for this theory was anecdotal and long term studies were not performed to prove that individuals that had sex assignment or reassignment shortly after birth had positive outcomes In fact, Money’s theories were based on one case study of a boy who was reassigned to the female sex after his penis was amputated during a circumcision. The boy was raised as a girl without being told what happened. Money reported that the patient had adapted well to life as a girl. Many years later, when the individual was located, it was discovered that the outcome was not as successful as had been originally reported. Joan (the patient’s female name) was never happy as a girl growing up and, in her teens, decided to live as a male, John. Eventually, John’s past was disclosed to him. He later married and became the adoptive father of two children .
9. Beh HG, Diamond M. An emerging ethical and medical dilemma: Should physicians perform sex asignment surgery on infants with ambiguous genitalia? Michigan Journal of Gender and Law. 2000;7(1): 1-63.