Infants and toddlers observe the voices, secondary sex characteristics, mannerisms, and dress of adults around them. In languages with grammatical gender (whether that’s pronouns in English or past-tense verbs in Russian), they also notice these references. They map their self-perception based on the adults whose gender presentation resonates with them. They do not learn about the reproductive apparatus associated with their assigned sex until later.
For children, gender precedes sex. To put sex before gender is to put the cart before the horse and express a lack of empathy, curiosity, and imagination about trans people and their internal experiences. People notice social roles first. (An example of this is how Henry Darger drew girls–since he’d never seen AFAB anatomy close up, he drew girls with penises—he mapped his own bodily characteristics onto his subjects. He wasn’t trans, as far as I know, but the analogy still holds up.)