Because "masculine" and "feminine" are societal concepts connected to gender roles, but are not in themselves, gender. The word gender is used in different ways by different people. I find it most useful to describe gender as the map in your brain of what to expect your body to be like. Essentially the sex of the brain. Usually the sex of the brain and the rest of the body match, so often that it's only relatively recently people are figuring out that's not always the case.
If your brain is mapped out to expect one set of sex characteristics, but you have the other set, it causes discomfort (dysphoria). I tried the "masculine woman" thing. Doesn't make dysphoria go away. Because I'm not a woman. My brain expects a flat chest, facial hair, male genitalia, etc. so having female sex characteristics in their place is disturbing. Surgery and HRT bring my body closer to matching what my "brain-body map" expects. Reducing the mismatch reduces the dysphoria and makes me a happier, more functional human being.
Some of what is considered "masculine" or "feminine" stems from simple biology. Males generally have more testosterone, which has certain influences on behavior. So does estrogen. But these are only generalities and very few people will fit perfectly into the gender roles built partially on that, partially on marketing, partially on... whatever else. It's a complicated subject and I'm not qualified to even try to explain it.
Medical transition basically does two things. 1, reduces dysphoria, makes one more comfortable in one's own body. 2, assists in being seen by society at large as one's actual gender (because again, brain/body sex mismatch is rather uncommon so most people instinctively assume your gender matches your looks).