Hormonal abnormalities are of several kinds. He has male gonads but female genitals, leading to a female gender identity. He is sterile, because he has no internal female sexual organs. Although the cause is unknown, it happens in 3 genetic males to every genetic female. There are at least two theories about how children learn gender roles via socialization.
Children learn that their behavior has consequences, rewards and punishments.
The language and instructions used leads to developing expectations. Modeling is also important. They learn by comparing themselves to others. Once gender is viewed as permanent, they strive to act role to provide internal congruence. Parents or primary caretakers model and reinforce gender roles.