How/where did Knuth define the famous \TeX macro?

The \TeX macro is defined in plain.tex as


or in LaTeX (ltlogos.dtx) as


(the difference is that LaTeX makes \TeX a robust macro, and adds the spacefactor correction \@).

You can use \show\TeX to see its definition in plain TeX, or in a recent LaTeX distribution, \ShowCommand\TeX:

> \TeX=robust macro:
->\protect \TeX  .

> \TeX =\long macro:
->T\kern -.1667em\lower .5ex\hbox {E}\kern -.125emX\@.
<argument> \TeX  
<*> \ShowCommand\TeX

This macro is hand-tuned to Computer Modern, so if you change fonts you might need to adapt the kerning.

The answer by Phelype Oleinik does give the definition for the TeX logo as it appears in the file plain.tex, but different values were used for the various kerns for other fonts that appear in the five volumes of Computers & Typesetting.

Knuth wrote an article for TUGboat explaining the differences and the reasoning behind the differences, and giving the values for fonts other than cmr in the Computer Modern family: "The TeX Logo in Various Fonts", TUGboat, Volume 7 (1986), No. 2, p.101

This answer adds nothing more than Phelype and Barbara already told you about the \TeX macro. However, for completeness sake, I just want to point out the existence of a command line tool named texdef that gives you the definition of TeX macros based on the provided parameters. In this case

[paulo@cambridge ~] $ texdef TeX

macro:->T\kern -.1667em\lower .5ex\hbox {E}\kern -.125emX

brings the original definition Phelype mentioned. By invoking the tool without any additional flags and options, texdef assumes TeX. If we explicitly ask for a LaTeX definition (-t latex),

[paulo@cambridge ~] $ texdef -t latex TeX

macro:->\protect \TeX  

\TeX :
\long macro:->T\kern -.1667em\lower .5ex\hbox {E}\kern -.125emX\@

the tool gives us the robust version as defined in LaTeX.