Details can't be given except this can only be done in cases where someone was badly fucked over by certain beings messing with the reincarnation process. Someone who would be a perfect female was incarnated as a male as some kind of "test" and then got depressed and suicidal because of this. Is that benevolent in any way at all? No it isn't. Some supposed "angels" or whatever they are, do things that can only qualify as extemely mean because they think they have the right to do this. You may have seen some people talking about (in these chans) how demons will trick you and try to rip you off, but noone expects any less from them. Angels on the other hand are religious zealots, they'll kill someone because of "the bigger picture" and will think they are doing it for "good", they also appear as stern and may punish people based on their own personal moral code. So it's really the angels you need to watch out for, you already know what demons stand for, so it's usually not an issue with them.
This may not be the reply you wanted but it's complicated. In the case of someone being about to kill himself over this, and the fault lies on those meddling "angels", it is possible to correct this. The body will be brought back to the state before the gender was determined, and then reformed all the way down. Changing physical reality is not the issue, it's the acceptence of other people and non-physical beings that stops this from happening in most cases. If a proper argument can be made, they will not block the magic, and it can be done.
Most people don't seem to understand that most higher tier magic is dependent on spiritual politics rather then just technical skills in the execution of spells.
It's not even needed that you personally perform any such spell, if you can make the proper argument some being may do it for you. It's not really that costly, energy wise. Molecules are low value matter and noone really cares if they are changed, as such. It's the implications of it that is the problem.
This is the reason why prayer may work. If you get it right, someone will fulfill your wish for basically nothing, just because you convinced them it was the right thing to do.
>Wouldn't they know just by looking at you?
It can't be widely known that this magic is available. See reply above, large groups of beings will not allow it. (Talking about it on the shitposting section of a site like this is ok.) So the people who know you will have their memories clouded, they'll just remember you were always masculine, and they'll find ways to explain away anything that doesn't make sense. The human brain is very good at explaining away any incosistances, you'd be surprised.