What is the contradiction in the proof of the halting theorem?
You actually have a missing detail on how the machine $TM_2$ is defined (and a bit of confusion between $TM_1$ and $TM_0$). Let's clear this up. You start by the assumption that there is a machine $TM_0$ that operates as follows. On input $x = &lt;TM_1, w&gt;$, the machine $TM_0$ answers &quot;yes&quot; whenever $TM_1$ halts on its input $w$, and $TM_0$ answers &quot;no&quot; whenever $TM_1$ does not halt on its input $w$.
Now we define a machine $TM_2$. On input $z = &lt;TM_1&gt;$ which a description of a machine, denoted $TM_1$, the machine $TM_2$ runs $TM_0$ on $x = &lt;TM_1, TM_1&gt;$ and returns the opposite answer of $TM_0$. In words, the machine $TM_2$ answers &quot;no&quot; when $TM_1$ halts on itself, and answers &quot;yes&quot; when $TM_1$ does not halt on itself.
To get a contradiction, consider what happens when we feed $TM_2$ to itself as an input. That is, consider the case where the input of $TM_2$ is $z = &lt;TM_2&gt;$. One of the following holds:

$TM_2(TM_2)$ = &quot;yes&quot;, and so in this case $TM_0(&lt;TM_2, TM_2&gt;)$ = &quot;no&quot;. Hence, by the definition of $TM_0$, $TM_2$ does not halt on itself.
$TM_2(TM_2)$ = &quot;no&quot;, and so in this case $TM_0(&lt;TM_2, TM_2&gt;)$ = &quot;yes&quot;. Hence, by the definition of $TM_0$, $TM_2$ halts on itself.

All in all, we have that by the two items above that $TM_2(TM_2)$ = &quot;yes&quot; iff $TM_2$ halts on itself, which is clearly a contradiction to $TM_2$'s definition (see the bolded sentence above).