The CHI specifically says that individuals who have had sex changes are not to be ordained to the priesthood.
As to the question of what might happen if someone didn't say anything until after ordination, I think this passage from Women and Authority: Re-emerging Mormon Feminism
Maxine Hanks wrote:
Gender-based distinctions may feel unnatural and wrong to many women. Some women feel they possess both masculine and feminine qualities; some have androgynous traits. The arbitrariness of gender-based privilege in exercising priesthood is illustrated in one example from the late 1980s. A former missionary elder underwent medical tests and was discovered to possess the complete reproductive and sexual organs of a female beneath a superficial, non-functional male organ. She had surgery to restore femaleness. Her temple marriage was annulled. It was decided that her priesthood would not be revoked, but she was told she could not exercise it. It was also decided that the priesthood ordinances she performed on her mission, including several baptisms, confirmations, and blessings, would stand as valid ordinances. When she was presumed to be male, she was allowed to exercise priesthood. People accepted her authority, felt the spirit of God, and considered her administration of saving ordinances to be valid. Yet she had the reproductive organs of a woman, not a man.
Her source for this story is a private interview with a person close to the subject. Or in other words, it is an anecdotal account---but a pretty plausible one.
In other words, there is no cosmic rule that says women can't
hold the priesthood, that automatically renders priesthood ordinances invalid if it's a woman performing them; it's that they don't
. If a woman were ordained because local leaders honestly believed she was a man and her true gender was later discovered, she would be forbidden from further exercising the priesthood and barred from holding any further offices of the priesthood, but she would still technically hold it and any ordinances she had performed would be binding and valid.
What I would really like to know is what the church would do if someone with a true androgyny condition like Olympic Gold Medalist Caster Semenya
decided to join the church. I imagine such a person would be treated in accordance with the gender they chose to identify with, and since Caster identifies as female, she would not be ordained even though she very probably has XY chromosomes.