The difficulty here is that people treat the concept 'gender' as though it is a simple, one-dimensional construct, when in fact gender is a complex phenomena involving biological processes, early socialization, and self-perception. It's misleading to say that gender is independent of biological sex, but it's also misleading to say that gender is entirely dependent on biological sex. What we can say is the following:
- The external features of gender (what can be seen with the naked eye, pun intended) are biologically superficial. They mainly determine social perception of gender, and play into later gender identification and sexuality
- Deep biological differences (in hormones, DNA, and the like) can produce gender-specific differences in behavior: e.g., increased testosterone can produce 'masculine' traits, while increased estrogen can produce 'feminine' traits. But not only can these be influenced medically, there is natural diversity between individuals and normal changes over the lifespan which means that men can sometimes be more 'feminine' and women sometimes more 'masculine'
- Neurologically speaking, 'identity' in general is poorly understood; any phrase of the form "I am ..." is a linguistic gloss over a lifetime of human interactions and experiences. We don't know how gender self-perception is formed, where it is encoded in the brain, or even whether it's a fixed element or something that can change
The best we can say is that at birth a human being has a predilection for a particular biological gender. This predilection is impacted heavily over time by social interactions and expectations, and cognitive reactions to such, producing a self-reflective feeling of 'maleness' or 'femaleness' that can vary in degree and focus. That variability (arguably) can be significant enough to place the self-reflective feeling of gender in opposition to the external biological signs of gender. The rest is a sociological question of to what extent an individual is obliged to conform to societal expectations.