I understand why it grates, particularly because I can't help but think the teacher would remember you were a Dr if you were a man
Another one who thinks this would be less of an issue if a man did it. "Professor" is a job title that you go through specific procedures for at work (at least in the UK). A PhD or MD is a qualification that legally entitles you to change your title on e.g. passport, driving licence, bank card. So you're getting someone's title wrong if they have the qualification and want to use that title. That said, I personally think it's different if you get it wrong for a man, because the alternative (Mr) is not linked to his marital status.
I fucking loath being called "Mrs". It isn't my name. I'm either Ms, or Dr, or my first name. Never fucking Mrs. If people then think I'm up myself, so be it.
Why are surgeons not called doctor
It dates back to a time when the medical profession was very clearly divided into apothecaries, surgeons and physicians. Physicians were much higher status, generally treated the rich, and did not get their hands dirty. They were also the ones qualified to use the title Dr, being university educated. Surgeons were more likely to have been through an apprenticeship system. They treated poorer people. Surgery was dirty and often unsuccessful (pre mid-19th century, changing in the second half of the 19th century). They did not have the status to use the title Dr.
As the professions have changed, surgery has become far more successful and higher status.Surgeons could use the title Dr in the same way GPs do - as an honorific, whether or not they hold an MD. But surgeons will often not want to use the title Dr. It's a kind of "fuck you, I may have been the underdog, but I won and I'm owning it".