Gender expression and gender stereotypes are societal constructs. A person's sense of their own gender is (probably) not. There have been many times where people have tried to raise their child as a different gender than the child was assigned at birth, and the child 99% of the time identifies with the gender assigned at birth, at the same rate as the general cisgender population. There have also been studies of identical twins where if one twin is trans, the other twin often is as well, at a much higher rate than fraternal twins.
There is a genetic component and a constructed component to gender.
Edit: wording.
Edit 2: See my comment below with sources on the twins study - it's possible I was misinformed on this. The results of studies are mixed.