Sex is a phenotype, not a genotype.
Genes do not directly dictate sex.
If there are certain types of damage the brain and body will even develop as female (see complete androgen insensitivity syndrome) so God’s recognition of a difference between men, women, and the mutilated or malformed is not obsolete.
God places them in their own category. Commandments on sexual morality still apply, and most of them are still mired in sexual sins, but there are also a lot of them (obviously not the hookers) who become celibate.
Sex is a genotype. XY = male. XX= female. There are sometimes birth defects that cause development out of the norm, but sex is ALWAYS determined by genetics.
A man (XY) who has his body mutilated to appear as a woman, is still a man. He can NEVER change the genetic code which is carried in every cell of his body.