There are plenty of misconceptions and associated drama that always comes up in discussion around this topic -
Male vs female gynecologists - It's not entirely a male thing - yes there are female doctors who are attracted to female patients
Men experience sexual stimuli differently than women - in particular they are much more visual - it's how male brains are wired. They do not unsee something they like
Men (or women for that matter) do not have a switch that turns sexual stimulus on or off. There is no special doctor's only super secret switch for this either
The concept of sexual relationship is different from sexual attraction - you can be in a committed relationship and have a profession as a doctor, auto mechanic, or software programmer and take notice of a sexual feature, a smile, someone's hair style, whatever....it just happens and it does not enhance or diminish your sex drive for the partner that you have a relationship with. It also does not imply that you lust after the person you noticed and act on that lust (of course it does happen but that's not my point...if you act out your lust and it's not reciprocal with the other person or you are in a committed relationship then you go to jail or get divorced regardless of your profession.
There's a lot more to it psychologically than this but if you apply the facts specifically to a male gynecologist who is not molesting his patients and who goes home at night to have wild sex with his wife you end up with a perfectly normal scenario ---
As part of his job he sees women all day, he may find one attractive, and he touches a part of her body that is associated with sex. He does this for a purpose other than sex but he still finds his patient to be attractive and thinks she has, let's say great looking breasts. He has the capacity to control his behavior but he still likes the feel of her breast, nipple, whatever. He keeps that to himself, conducts himself professionally, and moves along and takes the exact same course with a woman he does not find attractive...he could very well like the feel of her breasts also even though he finds her unattractive...and maybe feeling her breasts turns him off....but he still conducts himself professionally. Another doctor does the exact same examination but fails to conduct himself professionally and ends up in court accused of molesting the patient, the first doctor does not, even though both like breasts. It's not an off on switch, it's self control. If there is an on off switch then doctor number 2 cannot possibly be convicted of molestation....perhaps his switch failed but that's the fault of the switch not his personal behavior. There is no switch so doctor number 2 gets convicted due to his lack of control and his conduct.
So back to doctor number one. He goes home to his wife having felt breasts all day long. Surely he is bored with looking at and feeling breasts, heck maybe he is, maybe all his patients that day were unattractive to him and he is fed up with feeling breasts of women he finds unattractive. But there is a major difference with him and his wife - it's not transactional, it's emotional. He has a relationship and something totally different that he shares with his wife that he does not share with his patients. It makes zero difference that he has felt breasts all day....they are not his wife's....that is entirely different to the brain. It triggers entirely different nerve responses, hormonal responses, physical responses...there is no need for self control...so now when he feels breasts it's a completely different reaction in the brain even though what he sees and feels is the same as what he saw and felt the entire day.
And the moral of the story is this - sex is at best 1% physical and 99% mental. It's not that the "natural reaction" mentioned gets turned off and restored later....but it takes on very different forms in the relationship than it does during the professional hours. You could make the exact same comparison with a prostitute - when she is having sex for cash it's transactional...but it's still sex and maybe she likes what she does along the way. For the gynecologist it's transactional and he can still like what he does along the way. Yet both of them can have a relationship outside of their transactional experiences....and it's entirely different as far as the brain is concerned with what they do all day...or night...for a living.