Gender is identity based, and has always been identity based (since it's inception/coining in the 1950's), and what society depicts as the roles of said gender, what you'd expect of both genders, etc.
Yamato is sex based a female, but Yamato's gender is male.
It's really as simple as that. Gender and sex are different.
And even on the sex front, there are variances beyond xx and xy, through stuff like xxy and other variances, to people literally being in the wrong body, etc etc. It's honestly a million times more complicated than the dated middle school science classes teach, which is more a baseline for typical sex as we know it. There are plenty of research and studies into this and even as someone who knows about this stuff, a lot of it is even above my head. It's dealing with high level academia, peer reviewed studies/research, etc.
But most people just think back to that middle school biology class they took.
Kaidou is a better scientist than you guys.