In the proclamation on the family, the First Presidency and Quorum of the Twelve Apostles averred: “All human beings—male and female—are created in the image of God. Each is a beloved spirit son or daughter of heavenly parents, and, as such, each has a divine nature and destiny. Gender is an essential characteristic of individual premortal, mortal, and eternal identity and purpose.” From this we are assured that male and female reproductive organs and sexual characteristics will remain in their proper place as gender identifiers for all eternity, worlds without end. President Dallin H. Oaks defined “gender” in the Proclamation as meaning birth sex.
Misled people can make use of all the science and surgery they can to modify these identifiers in mortality, but in the next life (beyond the veil) they will see that they still have the same essential characteristics they were born with to those same Heavenly Parents in their pre-existent home. God our Eternal Father is a perfect resurrected and glorified being with all knowledge and all power and he knows how to put a male spirit in a male body and a female spirit in a female body and he has never made one mistake in this regard in all the history of the world; nor will He ever. According to Elder Vaughn J. Featherstone, “President Marion G. Romney said, ‘the God of heaven will never put a female spirit in a male body and he’ll never put a male spirit in a female body.’ You can write that down as God’s truth.”
For those exceedingly rare incidents of abnormality, where some confusion (on our part) is present with these organs, if nothing sorts them out before then, death certainly will. Surgery cannot affect the eternal spirit found within the body of a man or woman in any way.