I'm curious why genitals matter. I mean, yes, for doctors, that'll matter. But drivers license? Why is a gender needed? Passport? Are you John Smith... the male? Job application? Well, yes, for porn, it'd make sense, but for normal (Non-genital related work)... why does it matter?
It doesn't matter if you are a boy or a girl... you can do anything... but for the meantime, please fill out all of these forms detailing your genitals.
Who are you asking, the State Department?
Most forms that ask for gender. How did it get onto the forms in the first place? What is the origin?
I don't know the history of form development in the U.S., but I can relate my perception over my own lifetime (and through watching popular media from the 1970s and earlier).
In the 1980s and probably into the 1990s (in Australia at any rate) it was common to see 'sex' on most any form that was asking about sex. This led to many a sitcom joke where a character would write 'nil' or 'once a month' in the option. Presumably the sex field was asking for sex. Australian birth certificates and passports and many other documents have a 'sex' field.
At the same time, the term 'gender' was gaining currency as a polite-sounding synonym for sex, and it is still used by many people in this way today. I do not believe that 'gender', as a term, was applied to humans in any meaningful way before the 1960s. 'Gender' was a grammatical construct applied to nouns, not people. But soon forms had a 'gender' option that still really meant sex.
From about 2015, the explosion in gender ideology and trans activism has sought to replace 'sex' (not just the word, but the actual reality of it) with 'gender'--which is a thought in a person's head. For some purposes, this makes sense, but for others, it makes no sense at all.
A passport has a sex field because, presumably, it is (or was) one of the markers that helped identify people (along with their name and their picture and date of birth). It may be useful to add a 'gender' field to a passport, in cases where somebody's gender identity may lead to significant deviations in clothed appearance from what is expected given their sex.
I have not been overseas in many years, but I understand some body scanners are sexed, in that they are programmed to detect 'anomalies' based on the sex of the person being scanned. Here, the gender identity of the person seems to me completely irrelevant, and it is their sex that matters.