"The time has come for you to change your appearance, Doctor,
And begin your exile."
"The War Games"
Of all his incarnations, the Second Doctor was the only one who had his regeneration forced upon him when he didn't have any physical reason to undergo one.
This was done on Gallifrey, his home planet, and the Time Lords offered him several options to choose from for the next body he would inhabit. But he rejected them all for a variety of reasons - too old, too young, too fat, etc. After all, the Doctor was very particular about his appearance.
But to have all of these options at their disposal, with illustrations of what they would look like, the Time Lords must have had a DNA matrix in which genetic samples were stored, samples of the DNA from themselves, from each of their own previous incarnations. And these could be used again, perhaps with some tinkering on the combinations, so that certain incarnations would be seen once again in life.
So when the Second Doctor underwent regeneration and became the Third Incarnation of himself, it's pozz'ble, just pozz'ble, that a Time Lord looking quite similar had already been seen in Gallifrey's past.
And since a Time Lord could regenerate into almost any species or gender, why couldn't the template for the Doctor's new incarnation have come from a Time Lady?
Perhaps the DNA combination used was a donation from an earlier incarnation of Lady Flavia, or maybe even of the Rani. (I don't think it came from a past incarnation of the Master, or that evil Time Lord would surely have mentioned it upon meeting the Third Doctor for the first time.)
Whoever the Time Lady might have been, I think she could have looked something like this:
And then her malleable DNA sequence was adjusted to become the Doctor......
(We've seen DNA manipulated to swap gender in the show before - remember Jenny, "The Doctor's Daughter"?)