Wikipedia states on a disambiguation page that "the good doctor" is "a cliché referring to any physician." However, the earliest link on that page is to the Wikipedia article on Dr. Samuel Johnson (1709–1784)—while the earliest occurrence of "the good doctor" in a Google Books search is from almost a century before Johnson's birth. A biography of Thomas Fuller (1608–1661) attached to a three-volume set of his works dated 1662, refers to Fuller as "the good doctor" more than a dozen times, but it seems have been written sometime in the 1800s.
The Google Books search results for "the good doctor" show six matches between 1620 and 1700, distributed across the years 1620, 1655, 1658, 1662, 1687, and 1693. Here are the details of those earliest matches. From Samuel Hieron, "The Preachers Plea," in The Sermons of Master Samuel Hieron (1620):
It is a good saying of an ancient Father to this purpose : If my predecessors (saith he) either by ignorance or by simplicitie haue not kept and holden that which our Lord hath taught them by his example and authoritie, the mercie of our Lord might pardon them. But as the good Doctor saith, We cannot hope for the like, hauing better meanes of instruction. When the outward ordinary meanes failed, Gods hand was not shortned, but he was able euen in the midst of blindnesse, to saue those which belonged to the election of grace.
[[Update, December 7, 2021: Hieron evidently published this text in 1604 as The Preachers Plea: or, A Treatise in Forme of a Plain Dialogue Making Known the Worth and Necessary Vse of Preaching, and in that version of the text, a note identifies the good doctor as St. Cyprian.]]
From John Sargeant, Schism Disarm'd of the Defensive Weapons, Lent It by Doctor Hammond, and the Bishop of Derby (1655):
His thirteenth [chapter] is of St. Paul, who (saith he) appealed from the judgement of the chief Priests to the Tribunal of Cæsar. So as now Cæsar, a Heathen Emperor, is become Head of the Church; nay of two Churches (according to Master Hammond) the Heathenish, and the Christian. But the good Doctor is most grievously mistaken here, as he hath been almost in every place of .Scripture he hath yet produc't; & I observe, that though he be pretty good at mistaking all over his Book, yet when he comes to alleadge any thing out of Gods Word, he errs far more accurately.
The interesting thing here is that "the good doctor" is already being used sarcastically to describe, with exaggerated politeness, an enemy, Dr. Henry Hammond (1605–1660).
From William Sanderson, A Compleat History of the Life and Raigne of King Charles (1658), referring to events of August 1644 involving the siege of Hereford and its garrison commander Sir Barnabas Scudamore:
The wise men were admitted, and their secret counsel and advice was, To render up all to the valiant Scots; and so they parted. And the good Doctor [Doctor Scudamore] bringing them out of the Port had an unfortunate Shot from the Scot that killed him.
This being a sympathetic account of Scudamore's defense, it seems reasonable to take the characterization "the good doctor" here at face value.
From John Fell, The Life of the Most Learned, Reverend and Pious Dr. H. Hammond, second edition (1662):
Accordingly the good Doctor [Hammond] attended on his Master [King Charles I) in the several removes to Woburn, Cavesham, and Hampton-Court, as also thence into the Isle of Wight, where he continued till Christmas 1647.
This is one of eight instances of "the good Doctor" that Fell uses in the course of this book; Hammond is, of course, the same person whom John Sergeant ridicules as "the good doctor" in 1655. Since the first edition of Fell's work was published in 1661, five years after Sergeant's effort, it may be that "the good doctor" was a sobriquet applied to Hammond by his friends and admirers.
From Thomas Tenison's 1688 translation of Jean La Placette, Of the Incurable Scepticism of the Church of Rome:
How near to the truth doth the good Doctor [Canus (?)] approach? For first, he rejects not the Opinion of the Cardinal ; which if admitted, will soon put an end to the Controversie. Secondly, by the last clause of his Answer he confesseth that a Council free, and using requisite diligence, may pronounce contrary to the Faith.
From Stephen Nye, Considerations on the Explications of the Doctrine of the Trinity (1693):
They say farther, that 'tis not to be much regarded that so many have complemented Dr. Wallis for his Letters; for what Assurance have we that the Writers of them are not secret Socinians, and that they only banter the good Doctor?
Conclusions
All six of the earliest matches for "the good doctor" in Google Books search results appear to involve doctors of divinity, most of them (naturally enough) in the context of religious disputes. It doesn't seem to great a stretch to imagine the phrase "the good doctor" being associated in the first instance with religious figures like Thomas Fuller and Henry Hammond, and then with scholars like Samuel Johnson, and finally with physicians and scientists like the heroes of Dr. Doolittle and Dr. Who.
Update (December 7, 2021): Instances of the phrase from before 1620
My original answer did not include instances from Early English Books Online. so I have revisited it to included very early matches for "the good doctor" from an EEBO search. The search returns eleven unique matches, ten of which I reproduce here, starting with Jacobus de Gruytrode, The Mirroure of Golde for the Synfull Soule (1506):
Now vnderstand the fayre auctorite of saint Ambrose / he saithe that noo thinge is of so great cōmendacion towardes god as pity and charite / the good doctor sayde I haue beholde many bookes & scriptures butte I can not remember that I haue founde of any man: that wyllingly hath excersised the workes of mercy and pytie and viliously dyed And pope leo saithe he yeueth and sendeth to god precious and encere fruytis: that neuer lectyth the pore departe frome hym dispurneid or sorowfull.
...
So the myserable and dampned senners / shall euer be in desperacion / for so moche: as they shall knowe euer to de{per}te frome the payne sorowe & tourment {per}durable / & so as the good shalbe recōpensed with Ioye: the euyll shall haue for their heritage: sorow inestimable / like as saith the good doctor anselme / all they that by concupiscens of the flesshe passeth theyr dayes in this worlde: haue with theym in cōpany all the deuill{is} of hell / And saint Augustine saith to this purpose / god shall make glad / comforte / & enioy: all the felingis & witt{is} of the blessed people / by a spirituall dilectacion
De Gruytrode thus identifies two saints—Ambrose and Anselm—separately as "the good doctor."
From Johannes Carion, The Thre Bokes of Cronicles, Whyche Iohn Carion (a Man Syngularly Well Sene in the Mathematycall Sciences) Gathered Wyth Great Diligence of the Beste Authours That Haue Written in Hebrue, Greke or Latine (1550):
But within fewe dayes after, he [Alphonse Diasy] came to Newe burgh agayne from Ausburgh, where he had prepared good post horses to be in a readynes to flee when he should se cause. And when he came to the sayde towne of Newburgh early in the mornyng at the openyng of the gates, he taryed hymselfe before the gate with the horses, and sent his seruaunt (beyng a murtherer, whome he had hyred at Rome for suche affayres, and brought hym forth with hym) into the towne with a lettre, who whan he came to the sayde Iohn, delyuered hym the sayde lettre, and whyle he red the same, the Murtherer {"The good doctor Iohn Diasy murthered."} smote hym with a greate sharpe halbarde and cleft his hed in twayne, that he fell downe dead, but the Murtherer ranne out of the towne, to hys Maister, so that both the Murtherers gate themselues awaye.
The key sentence here seems to appear as a side note or marginal subhead in the text, and "the good doctor" appears to be a reference to John Diasy, who is described earlier as "learned in the Latin, Greke and Hebrue tongues." Alphonse Diasy, who hired the murderer to assassinate his brother, is identified as "a Doctour of the lawe and at Rome in hygh office, a seruaunt of the Pope, and an enemy to the Gospell of Christe"—and so is clearly not a "good doctor."
From a 1566(?) translation of Pierre Boaistuau, Theatrum Mundi the Theatre or Rule of the World:
For this is of a suretie, that there are pastors that haue this twentye yeares receyued the fruites of their benefices, that haue not thrée times visited their flocke, but they commit them to poore ignorant Chaplens, and many times to those that will serue best cheape, who as they serue God by credit, and by procurement, if that the Lorde God haue not pitie of them, they shalbe damned for euer. The which being considered by the good Doctor S. Bernard, toward the ende of the .33. sermon of Canticles, is very sore offēded with them, complaining of their pompes and superduities, whereas he painteth them out in their liuelye coulors, as followeth: there is (sayeth he) a spot and plague corrupted, that raigneth in the whole body of the Churche, the Ministers of Iesus Christ serue Antichrist, they stande and goe in great ho∣nor and pomp with ye Lords benefits, & neuerthelesse, they giue no honor to his name, and it is the ornament of a harlot, whom thou séest daily procede from thence, so is the golde that they carie, their saddels, bridels and spurres, the ornament of their féete is more superbious and full of pomp than the temple of God: ...
Here, again "the good doctor is a saint—in this case, St. Bernard.
From a 1575 translation of Jean d'Albin de Valsergues, A Notable Discourse, Plainelye and Truely Discussing, Who Are the Right Ministers of the Catholike Church Written Against Calvin and His Disciples, ...:
If that the good doctor S. Cyprian had beene in these our daies, might he not well haue saide against youre Schollers, that which he did write against Nouatus? there needed no other, but in steede of Nouatus to put in Caluinus or Zuinglius; et nomine mutato, de vobis fabula narrabitur.
Seing that the saide S. Ciprian doth holde & affirme, that Nouatus oughte to be accompted as no Bishop, because he succeded no bodie, but rather that he did make himselfe a Bishop, without anye imposition of handes. Then to what purpose, I praye you, are ye of the opinion, that Caluin and Zuinglius are such faithful ministers, considering that they are as far from prouing yt confirmation of their mini∣sterie, as euer was Nouatus.
The good doctor here is once again St. Cyprian.
From a 1577 translation of Guy de Brès, The Staffe of Christian Faith Profitable to All Christians, for to Arme Themselues Agaynst the Enimies of the Gospell:
O foolish Galatians, who hath bewitched you that ye should not obey the truth? to whom Iesus Christ before was descrybed in your sight, and among you crucified.
Epiphanius the good Doctor in the Epistle written vnto Iohn Byshoppe of Ierusalem, and afterwarde translated by S. Ierome out of Greeke into Latine.
The "good doctor" in this case is St. Epiphanius of Salamis.
From a 1583 translation of Pietro Martire Vermigli, The Common Places of the Most Famous and Renowmed Diuine Doctor Peter Martyr:
For by this little sparke [free will], they would boast, that they are discerned from others: but [the scriptures] will not haue them discerned, otherwise than by the grace and mercie of God, not by free will, or by [their owne] gifts and vertues. Of which matter, thus Augustine wrote in his booke De praedestinatione sanctorum, the fift chapter: For are men discerned from men, by those gifts, which are common vnto all men? But here he first said; For who separateth thee? And then he added; And what hast thou that thou hast not receiued? Bicause a man, being puffed vp against another man, might saie; My faith, my righteousnesse, or if there be anie thing else, discerneth me. Such cogitations the good Doctor preuenting saith; What hast thou, that thou hast not receiued? And of whom, but of him which hath separated thée from another? To whom hath he not giuen that, which he gaue vnto thée, &c.
St. Augustine is evidently the good doctor in this instance.
From Master Broughtons Letters, Especially his Last Pamphlet to and Against the Lord Archbishop of Canterbury, about Sheol and Hades, for the Descent into Hell, Answered in Their Kind (1599):
Whatsoeuer is sound in thy [Hugh Broughton's] writings it is borrowed: but the Lunaticall conceits, which therewith are blended, are thine owne. And this is sufficient for your first great challenge of his Graces [the Archbishop of Canterbury's] vnlearnednes, his ignorance of the Rabbins traditions, viz. the opprobry of Christianitie, and the scumme of Diuinitie. Wherein least you should be counted as the onely malicious slaunderer, and detractor of so reuerend a person, you call to witnes D. Sarauia, who told you, asse you say, that he could not beate into his Graces head the bare conceit of your deep studies. Yea but D. Sar. cries out, Os impudens, and requested one to tell you that you did falsly belie him in this, and wheresoeuer in this kinde you name him: and thinkes verely it is but your spleene against him, breaking out in reuenge of an old quarell: for your Mastership being in loue with a rich Marchant strangers daughter, and vsing the good Doctor as a mediatour for the match, the father a wise graue man, but once hearing of Broughtons name, in no case would admit his daughter the speech or presence of such a giddie headed Lysard: and vpon this you raued in your passions against the Doctor, chafing extreamely that he had not sufficiently commended you so highly as you deserued. And therefore he takes this to bee but the〈in non-Latin alphabet, and vomit of a cholericke stomacke, to make him an author of a malicious slaunder.
The good doctor is Hadrian à Saravia, a Dutch Calvinist who translated the first twelve books of the Old Testament in the King James Version of the Bible.
From a 1600 translation of Cypriano de Valera, Two Treatises the First, of the Liues of the Popes, and Their Doctrine; the Second, of the Masse:
This Pe[d]ro Mexia was a man very superstitious, and wholly a Papist, who procured what he might to quench the light of the Gospell, which at his time in Seuill was kindled. He greatly persecuted the good Doctor Egidius, or to say better, Christ in Egidius and other his members. Notwithstanding that he was so great a Papist, yet could he not but speake, & note so great an infamy & blow to the Church of Rome [as the naming of a woman to be Pope].
I don't know who this Egidius is, although it might be Aegidius [Giles] of Viterbo, a reformist cardinal who died in 1532—but de Valera says that Mexia's perseccution of Egidius occurred "about the yeer 1550," so the timing is quite iffy.
From Hugh Broughton, A Defence of the Booke Entitled A Co[n]cent of Scripture for Amendment of Former Atheian Most Grosse, and Iudaique Errours, Which Our Translations and Notes Had: Against the Libel, Scoffing a Scottish Mist ... (1609):
I sent to the learned & gratefull Doctor [Richard Bancroft] these three bookes bound togeather, Our Lordes Familie, honouring the K. Coheleth, and Lamentations, given to P. H. and I thought he had so much witt as to give sage thankes, as they that bee made Lordes without giving money to friends, to come by their title: but I was farre deceaved. He raved and saide, the Kings Knight was a lying flatterer. And that the K. gave no promesse, that he might give the lie to the K. too, and threatned that he would stay the King.
But if I can prooue he chirpeth one syllable to hinder the opening of our glorious Gospell to the Iewes, and driving off all Christians to their desired consent of agreement for story: as Papistes, Lutherans, Genvaees sage Preachers, and our BB. all but twoo silver Speared, wishe: Franckfurt Mart shall beare me witnesse I will give in Ebrew and Greeke to D. Bancroft that knoweth neither, the good Doctor, the Anathema. Maran, Atha, that as wicked Ioakim was buried like an Asse for burning the infinite pleasant witty sixfold Alphabeted Lamentations of Ieremie, which matter I touched aboue. So that Richard Bancroft may be with all Christians wishe, an other Vladislaus for toying with the glo∣rious Gospell of our salvation.
This is the same Hugh Broughton whom we met in 1599. He refers to Richard Bancroft first as "D. [that is, Doctor] Bancroft" and subsequently—and with utter contempt—as "the good Doctor." This marks the first instance I've been able to find of sarcastic use of "the good doctor," and it comes 46 years before the instance from John Sargeant noted in my original answer.
From Humphrey Leech, A Triumph of Truth: Or Declaration of the Doctrine Concerning Euangelicall Counsayles (1609):
Thus the good Doctour [Kilby] soundly, plainely, and, on all parts, charitably afforded him [Doctor Hutton] his friendly advise. And herevpō it was, that Doctour Hutton was satisfied; whereof he gaue sufficient signes, when he receyued the aforesaid copy [of Leech's sermon].
Dr. Kilby was, according to both sides in this controversy over allegedly heretical views, "a very graue, & learned Doctor in that Vniversity," "that excellent patterne of learning, life, and governement Doctor Kilby" "this graue and worthy Doctor," "the venerable Docotor," "the Reverend Doctor" etc., so clearly the attribution "the good Doctour" in this case is sincere.
Further conclusions
Five of the earliest six published works in the EEBO database that mention "the good doctor" use the expression in reference to a saint, suggesting that a strong connection may have existed early in the life of "the good doctor" in English between that phrase and the notion of a learned saint.
I should note, however, that several additional sixteenth-century texts use the plural form "the good doctors," usually in reference to the early (or not-so-early fathers) of the Catholic Church. Taken together, the evidence for "the good doctor" originating as an appellation for a saint is not overwhelming, but the use of it to refer to a learned and venerable religious figure is very strong.
Thios makes the sarcastic use of "the good doctor"—from as early as 1609—quite striking, and indeed almost shocking, given the uniformly pious use of the expression in previous publications.