Gender and sex aren't the same thing, a distinction that seems to have eluded you. Fortunately, most major countries are beginning to recognize this.
"The U.S. issued its first passport with an "X" gender designation on Wednesday—but it's far from the first country to recognize citizens who don't identify as either male or female.
At least 15 countries have already allowed people to amend their gender to a legalized non-binary or third gender identifier on their passport, including Argentina, Austria, Australia, Canada, Colombia, Denmark, Germany, Iceland, Ireland, Malta, the Netherlands, New Zealand, Pakistan, India and Nepal.
In 2019, Canada introduced gender-neutral passports with an X category after a number of provinces made non-binary markers available for birth certificates and driver's licenses two years earlier."
https://www.newsweek.com/which-countries-recognize-third-gender-option-passports-1643167