Seems to be that whether it's mandatory or voluntary is based on one's sex, not on any sort of identity.
Which makes sense otherwise a lot of males would be able to opt out by claiming that they are women in their minds or souls or in enactment of gendered stereotypes or whatever it could possibly mean to identify as the opposite sex.
Men are the ones used as cannon fodder mostly because from a reproductive point of view they are more disposable. They also tend to be physically stronger so are more suited to many combat roles that require raw strength.