First: No, magic won't change gender. Choosing gender changes gender, and if you're epiphenomenalist like I am... that's more like agreeing to a gender that your subconscious chose for you anyway. In any case, magic doesn't work on physical shapeshifting.
Second: To my understanding, there's a difference between sex and gender. Sex is the physical part of it, like a scientist would define species that reproduce sexually (like a human) based on genitalia. The societal gender is an entirely different thing, but it gets complicated to consider something in-between: genitals, chromosomes, hormones, neurological structure, are all bodily functions that contribute to a person's sense of their own gender...and I haven't even gotten to societal expectations yet!
So, even if somebody has XY chromosomes, if the striae terminalis region of their brain is of a certain proportion more appropriate to women, or their hormonal production is more feminized, or even--especially--if they vocally want to be considered a woman by society, then as far as I'm concerned? They're a woman.
(Actually, that someone says they want to be considered as such in society is probably the only time I should agree, because it's kind of offensive to go, "Oh, haha, you've got estrogen in your system so you're not a real man" when everybody has a little estrogen in their system, and the one I'm saying that to would rather be considered a man, because I'm not a medical professional that this person specifically solicited to go meddling and measuring his hormonal balance.)
It might get complicated if the individual in this example wants to be a... how to put it? ...breeding woman, but then again sometimes women have fertility issues. Being born without a womb and with male genitalia would just so happen to be a much rarer complication than, say, irregular ovulation that can probably be solved with some herbal teas.
- female is the sex
- woman / feminine is the gender
- male is the sex
- man / masculine is the gender
- androgyne is another gender
- intersexed is the sex (XXY chromosomes; fetal development of both reproductive organs, not necessarily having to do with the chromosomes--etcetera.)
- sex and gender tend to correspond (intersexed with androgyne, male with masculine) but not always.
Magic doesn't change sex.
Some magic glamours might maaaybe help with gender as in how other people view your gender-based position in society, but not that much.
Phew! Sorry this was so long, but just in case people would like more perspective of why gender changing spells are impossible rather than just: Yes they're impossible.