Faults in the halting problem reasoning
The proof you wrote in the question is faulty, because it uses the wrong definition of the Halting oracle. You tried to fix the proof by inserting the assumption $X(X) = X$, but that is not the way to do it. Here is the correct proof.
Definition: A halting oracle is a machine $H$ which takes as input a pair  $(M,I)$ where $M$ is the (description of) a machine and $I$ an input. $H$ always  halts and outputs:

&quot;yes&quot; if $M(I)$ halts,
&quot;no&quot; if $M(I)$ does not halt.

Theorem: A halting oracle does not exist.
Proof. Suppose $H$ exists. We shall derive a contradiction.
Let $N$ be a machine which does the following upon receiving an input $I$:

if $I$ is &quot;yes&quot; then $N$ loops forever,
otherwise $N$ halts.

Let $X$ be the machine which takes an input $I$ and then acts as $N(H(I, I))$. We now prove two contradictory facts:

$X(X)$ does not halt.
$X(X)$ halts.

To prove the first claim, suppose $X(X)$ halts. Then $H(X,X)$ outputs &quot;yes&quot;, therefore $X(X) = N(H(X,X)) = N(\text{yes})$, but $N(\text{yes})$ does not halt. Therefore it is not true that $X(X)$ halts.
To prove the second claim, suppose $X(X)$ does not halt. Then $H(X,X)$ outputs &quot;no&quot;, therefore $X(X) = N(H(X,X)) = N(\text{no})$, but $N(\text{no})$ halts. Therefore it is not true that $X(X)$ does not halt, so it halts. $\Box$.