So far I have been unable to find the original source for the story mentioned in the question. However, there are multiple mentions of this incident in the general literature about Einstein. All accounts agree that the teacher was Dr. Ferdinand Ruess, who taught at the Luitpold-Gymnasium in Munich, the high school that Einstein attended from 1888 to 1894.
Denis Brian, "The Unexpected Einstein", Hoboken, NJ: Wiley 2005
Nor to the one teacher he really liked, a Dr. Ferdinand Ruess, who taught history and German. [...] Many years later, probably in 1909, Einstein returned to the school to call on Dr. Ruess, who did not remember him. Einstein was poorly dressed and assumed that Ruess suspected that he was a stranger down on his luck who had come to beg, borrow, or steal from him. Einstein ended the embarrassing encounter with a quick exit.
Carlos I. Calle, "Einstein For Dummies", Hoboken, NJ: Wiley 2005
Another teacher there, Dr. Ferdinand Ruess, was different from the rest. Instead of emphasizing memorization and passive acceptance of facts, he made the students think for themselves. He inspired in them a love for German literature and for the study of ancient civilizations. Einstein had a great appreciation for Dr. Ruess. Later in life, when Einstein was famous, he decided to pay his old teacher a visit. As often happens, Ruess didn’t recognize his former student. Seeing Einstein in his usual baggy and worn-out clothes, Ruess mistook him for a beggar and had his maid throw him out.
Ronald W. Clark, "Einstein: The Life and Times", 1971 [Thanks to @kimchi lover for the pointer in comments]
At the Gymnasium there appears to have been, as there frequently is in such schools, one master who stood apart, the odd man out going his nonconformist way. His name was Reuss. [...] In later life Einstein would recall how Reuss had tried to spark alive a real interest in ancient civilizations and their influences which could still be seen in the contemporary life of southern Germany. There was to be an unexpected footnote to Einstein's memory. For after his first work had began to pass a disturbing electric shock through the framework of science, he himself visited Munich and called on his old teacher, then living in retirement. But the worn suit and baggy trousers which had already become the Einstein hallmark among his colleagues merely suggested poverty. Reuss had no recollection of Einstein's name and it became clear that he thought his caller was on a begging errand. Einstein left hurriedly.
Gerald Holton, "Einstein and the Cultural Roots of Modern Science." In: Peter Galison, Michael Gordin, David Kaiser, eds. "Making Special Relativity", Routledge 2001
then, under the supervision of his only beloved teacher, Ferdinand Ruess, poems by Uhland, Schiller, Goethe, and others;
The curriculum notes in the Einstein papers at Princeton suggest that in addition to German and history, Dr. Ruess also taught Latin and Greek and was Einstein's Ordinarius (a function analogous to an American home room teacher) in 1893/1894.
If we accept the dating of the incident to 1909, it is likely that it happened during a stopover in Munich as Einstein traveled from Switzerland to Salzburg to give a talk at the 81st Meeting of German Scientists and Physicians (Versammlung Deutscher Naturforscher und Ärzte) in Salzburg on September 21, 1909: "Über die Entwicklung unserer Anschauungen über das Wesen und die Konstitution der Strahlung" (On the Development of our Views Concerning the Nature and Constitution of Radiation).
I was able to find the scan of an unnamed publication in Google Books that contains some biographical data on Dr. Ruess:
RUESS, Ferdinand, Gymn.-Prof., Dr. — *30 V 1853, Augsburg. — V: Matthias R.; M: Viktoria gb. Bach. — Gymn. Augsburg; Univ. München, Würzburg. — Verh.: 82 m. Karoline gb. Schmid T v. Georg S., Fabrikant München — K. Hermann *80. — 75 Assist. am Realgymn. Würzburg; 80 Gymnlehr. in Neuburg a. d. Donau; 93 Gymn.-Professor am Luitpold-Gymn. München — W: Tachygr. d. Röm. 79; Griech. Tachygr. 82; Progr. üb. Tiron. Noten 83 u. 89; Stenogr. Wörterb. 96, 00, 03, 06; Lehrb. d. Gab. Stenogr. 04 — L-B: Alte Tachygr.; Gab. Stenogr. — 1. Vors. d. Gab. Sten.-Zentralver.; Mitgl. d. Prüfgskomm. f. d. Lehramt d. Sten. — Ehrenmitgl. mehr. Sten,-Ver. — München, Steinsdorfstr. 6 III
Ferdinand Ruess was born on May 30, 1853 in Augsburg, attended the local high school there and subsequently studied at the universities of Munich and Würzburg. He started working as a teacher in the latter city in 1875. He married the daughter of a Munich industrialist in 1882. He had a keen interest in shorthand and published several books on ancient Greek and Roman shorthand as well as modern shorthand and was a member of the Munich stenographer's association (Stenographenverein). The Internet Archive provides a high-quality scan of his 1882 book "Ueber griechische Tachygraphie" (On Greek Tachygraphy).
Some additional biographical details and a picture of Dr. Ruess are provided in a publication related to the Gabelsberger stenography association:
K. Heck, "Geschichte der Schule 'Gabelsberger', Zweiter Teil," Wolfenbüttel: Hecknersche Druckerei 1902.
From this we learn that he started working at the Luitpold-Gymnasium in 1887 and was promoted there to the rank of Gymnasialprofessor in 1893.
A curious side note, which to me sheds some doubt on the story in the question, which may thus be apocryphal.
In 2018 some postcards sent to Einstein were put up for auction. Among these is a postcard by Dr. Ruess in Munich, written in shorthand and dated September 23, 1900. This would seem to indicate that the teacher was corresponding with Einstein after he left high-school, making it less likely that he wouldn't have recognized him by name in 1909. The scan of the postcard provided by the auction house is of sufficient quality that someone with knowledge of Gabelsberger shorthand could decipher and transcribe it.
The postcard is potentially a reply to a letter by Einstein. In a letter to Mileva dated September 19, 1900 preserved in the Princeton Einstein papers he mentions writing a letter to a former teacher in Munich, who may well have been Dr. Ruess:
Gestern hab ich in einem launigen Stündchen einem meiner früheren Lehrer in München, den ich besonders gern hatte, einen Brief geschrieben, will sehen, ob er mir vielleicht was drauf antwortet.
Addendum: Thanks to Andreas Lauschke and a second person, each of whom supplied me with a partial transcription of the postcard, it is clear that this is indeed Dr. Ruess's reply to Einstein's letter. Dr. Ruess writes that he was quite surprised to receive the letter, states that he read about the developments in Einstein's life with interest, and congratulates him on the recent conclusion of his studies (Einstein had received his teaching degree, Diplom als Fachlehrer in mathematischer Richtung, from Polytechnikum Zürich in late July 1900).