IMHO recording gender is outdated. It really serves no purpose. Back in the old days identity papers would also show occupation and religion. Fortunately those days are gone and gender is next if you ask me.
Only biological sex should be recorded, since "gender" is a made up concept that can be changed at will.
Same reason for not having occupation and religion listed on government ID.
What about those with XXY, XYY, etc chromosomes?
That's what "Neither" or "Other" is for. Some passports have an 'X' option for people who are not 'M'/'F'. But I agree, it's an outdated concept anyway, since you can get someone who clearly identifies as a male but who dresses as female, or vice versa, or anything in between, it's perfectly acceptable in this day and age after all (in most countries & to most people).
For medicine having biological sex is relevant, as there are some diseases and conditions that only impact certain sexes.