I had an exam in probability theory yesterday, so these topics are still quite fresh in my mind. The confusion already starts when he uses the equation
E[X] = \sum_{i=1}^{\infty} x_i p(x_i)
for the expectation. In my class it was introduced as
E[X] = \sum_{\omega \in \Omega} X(\omega) P(\omega)
= \sum_{ x \in X(\Omega)} x p_X(x)
which totally makes sense if you know that X is a function that assigns a value to each possible outcome. In most cases we don't actually care about the outcomes, so there is the second description using p_X.
The subscript X is important to highlight that p is not just some arbitrary function, it is p_X, the probability mass function of X.
Now when you want to compute the expectation of X^2, you use
E[X^2] = \sum_{\omega \in \Omega} X^2(\omega) P(\omega)
= \sum_{x^2 \in X^2(\Omega)} x^2 p_{X^2}(x^2)
i.e. the substitution he wanted to do actually works when you make the dependency of p_X on X explicit.
Now p_{f(X)} is not that easy to compute from p_X in general, because you have to account for multiple possible ways to reach the same value, e.g. x^2 = (-x)^2. For f(x) = x^2 we have
p_{X^2}(x^2) = p_X(x) for x = 0
and = p_X(x) + p_X(-x) otherwise
If f is more complex, there is a third way using
E[f(X)] = \sum_{x \in X(\Omega)} f(x) p_X(x)
which amounts to the same thing, but is usually easier to calculate.