My own feeling is that it is important for my doctor to know about my gender identity. I present as a woman, so without that knowledge, my doctor would not know to check my prostate, for example. Plus, I rely on her to prescribe my hormones, and she needs that information to do so effectively.
But it does out you. If you are not ready for that, I can understand not telling them. You may not have that degree of trust in the individual doctor, or in specialists that you might get referred to. Perhaps the state you live in does not permit doctors to be supportive.
So there are reasons for and against. My own preference is for my doctor to know all about me in order to receive the best possible care.