"And if the doctors are so concerned, then why not require genetic testing in doubtful cases and correctly inform the parents of their child's sex? At that point the parents could work with their child's given gender rather than against it."
Gender identity does not always go along with genotype. The completely AIS women are a good esample. AIS women are phenotypically female. Partial AIS women may be born with somewhat ambiguous genitalia.
Again: Why not ask the child to which gender they should belong.
I believe it is better to ask the child than the parents, but you can't ask the child and expect an intelligent response until they are old enough ... and the definition of "old enough" is itself subject to lots of debate.
In the case of AIS, it would seem best to do nothing rather than force the child onto some male hormone regimen. But in other cases it might be best to push the child medically to look outwardly corresponding to the inner reality rather than just to force the child in the direction closest to the way they appear by way of their genitalia, i.e. have the dog wag the tail rather than vice-versa.
When the child comes of age, he/she is owed a complete explanation by his/her parents, and in turn he/she should be expected to explain his/her situation to any prospective suitors. Unless the suitors have made it clear they don't care what sex he/she is.
The AIS condition seems like it may be amenable to a medical "cure" at some point in the future. In the mean time it seems crazy that most religious texts place a greater premium on sexual identity than the Creator who would allow all of these exceptions to come about.
Either these cases are a result of sin (e.g. drugs, booze, smoking during pregnancy leading to birth defects) and the children are its victims, or else some re-interpretations are in order.