"There are two competing narratives here, both asserted, neither especially well evidenced."
I disagree. We know that a person's gender identity is inbuilt, not learned, because of a giant unplanned experiment that has been carried out over the last several decades, during which doctors reassigned thousands of baby boys to female.
Until quite recently, the prevailing theory was that people are born "gender neutral", and develop male or female behaviour, preferences etc (and a male or female gender identity), from how they're treated by the people around them during early childhood. On the basis of that theory, it became the usual practice to perform sex reassignment surgery on baby boys with damaged or otherwise abnormal genitals (this was done because it's much easier to surgically construct a vagina than to replace a damaged or missing penis).
Then, in the late 1990s, word got out that the "index case" on which the gender neutrality theory was based had gone horribly wrong. Despite having been surgically reassigned to female during infancy and raised as a girl, David Reimer had, as an adult, rejected the female identity and was now living as a man. Scientists went back and checked up on other cases where infant boys had been reassigned to female, and found that the same thing that had happened in the David Reimer, had happened in a very high percentage of these other cases too. In some of the studies it looks like they found a failure rate approaching 100 percent.
Here's some examples of what these studies found:
- "Discordant Sexual Identity in Some Genetic Males with Cloacal Exstrophy Assigned to Female Sex at Birth"
www.ncbi.nlm.nih.gov/pmc/articles/PMC1421517/
"Eight of the 14 subjects assigned to female sex declared themselves male during the course of this study, whereas the 2 raised as males remained male. Subjects could be grouped according to their stated sexual identity. Five subjects were living as females; three were living with unclear sexual identity, although two of the three had declared themselves male; and eight were living as males, six of whom had reassigned themselves to male sex. All 16 subjects had moderate-to-marked interests and attitudes that were considered typical of males..."
- "Psychosexual development in genetic males assigned female: the cloacal exstrophy experience."
www.ncbi.nlm.nih.gov/pubmed/15183379
"Studies of 29 children revealed that despite the absence of the typical postnatal and pubertal androgen surges and the presence of female genitalia, all female-assigned subjects displayed a marked male-typical shift in psychosocial and psychosexual development. Nearly half of them have declared themselves male..."
- "A 7-year experience of genetic males with severe phallic inadequacy assigned female."
www.ncbi.nlm.nih.gov/pubmed/15538277
"All patients demonstrated marked male typical behaviors and interests. Of the 15 female assigned patients 1 died, 1 refused to declare sexual identity or orientation, 1 converted to male before initial evaluation, 1 was reassigned male by the parents and 5 others declared male sexual identity. Thus, of 17 living patients 10 live as males and 6 as females. Of patients 17 years or older only those living as male lived independently. The 4 oldest patients living as male but only 1 patient living as female would discuss sexual orientation-all 5 declared orientation toward females, and 3 of these 4 males had girlfriends or were married..."
Remember, these are all children who were male at birth, but surgically reassigned to female during infancy and raised as girls. Despite being given a vagina and treated as girls by their families, most of the people put in this situation have adopted a male identity as soon as they were old enough to do so. From these cases and others, it's abundantly clear that there are physical differences between male and female brains that arise before birth, and determine gender identity later in life. Your gender identity, like your sexual orientation, is hardwired, not learned.