You're kind of close to getting it, actually. Even with your mindset, even with your assumptions, your own reasoning has already put your finger on the fact that "male/female" might be an inadequate dichotomy in a certain situation - that there might be some good reasons why male/female might not make sense for an individual.
Now imagine that, with some thought and research, you can think of another situation where a gender binary seems odd, then another, then another, over about a hundred and fifty years of study. Because that's how long it's been, by the way, since this became a field of Western scientific research.
And to someone who hasn't studied it, it seems like "where did all these 'new' genders come from?"
Well, it came from moments exactly like what you just experienced. All across human medicine with all the weird and wonderful things our bodies and minds can do if a hormone is out of balance, or a protein isn't expressed, or a neurochemical is made, or who knows what else - is it really so difficult to believe that weird things happen with sex and gender?