A baby may be born with a penis but no testicle. The hospital would do genetic tests to determine whether the baby was genetically female or male. In the case of a genetic female born with a penis the routine procedure would be to surgically correct the growth at an early age. These tests obviously did not exist at the time the torah was given, would the presence of a penis or a vagina render the child male/female (in terms of halacha) irrelevant of the genetic test results or would halachic follow the genetic makeup rather than an external sign. Does halacha follow the medicine and declare a baby female based on test results even if the baby is born with a penis or does the halacha follow the obvious external signs which most of us would assume render the baby male.
Nishmat Avraham Even Haezer Siman 1 Saif 5 says the following:
The sex of the child is determined by the sperm. Some sperm carry the X chromosome and the others the Y chromosome, whereas the egg always carries the X chromosome. Thus, if an egg is fertilized by a sperm carrying an X chromosome, the resulting baby will have an XX paired chromosome and will be a girl. If the egg is fertilized by a sperm carrying a Y chromosome, the resulting baby will have an XY paired chromosome and be a boy.
In Yoreh Deah of Nishmat Avraham Siman 262 Saif 4:
The Rambam defines an androgynous as someone who has both male and female genitalia and we are therefore uncertain as to whether he is a male or female. He has no sign and never will have by which one may establish whether he is a definite male or female. The Raavad disagrees and writes that an androgynous is half male. The Shulchan Aruch holds like the Rambam whereas the Rema quotes an opinion that he is a certain male.