[proofplan]
We first check that all quantities in the formula are finite: the finite second moment implies that $X$ is integrable, and then the centered square is integrable. After setting $m:=\mathbb E[X]$, we expand $(X-m)^2$ pointwise and integrate the resulting identity. The probability normalization $\mathbb P(\Omega)=1$ then reduces the expression to $\mathbb E[X^2]-m^2$.
[/proofplan]
[step:Show that the expectation and variance are finite]
Define $m\in\mathbb R$ by
\begin{align*}
m:=\mathbb E[X]=\int_\Omega X(\omega)\,d\mathbb P(\omega),
\end{align*}
after verifying that this integral is finite. For every $\omega\in\Omega$,
\begin{align*}
|X(\omega)|\leq \frac{X(\omega)^2+1}{2},
\end{align*}
because $(|X(\omega)|-1)^2\geq 0$. Since $\mathbb P(\Omega)=1$ and $\mathbb E[X^2]<\infty$, monotonicity of the [Lebesgue integral](/page/Lebesgue%20Integral) gives
\begin{align*}
\int_\Omega |X(\omega)|\,d\mathbb P(\omega)
\leq
\frac{1}{2}\int_\Omega X(\omega)^2\,d\mathbb P(\omega)
+
\frac{1}{2}\int_\Omega 1\,d\mathbb P(\omega)
<\infty.
\end{align*}
Thus $X$ is integrable and $m$ is well-defined.
Now define the centered square [random variable](/page/Random%20Variable)
\begin{align*}
Y:(\Omega,\mathcal F)&\to(\mathbb R,\mathcal B(\mathbb R))\\
\omega&\mapsto (X(\omega)-m)^2.
\end{align*}
For every $\omega\in\Omega$,
\begin{align*}
Y(\omega)=(X(\omega)-m)^2\leq 2X(\omega)^2+2m^2.
\end{align*}
The right-hand side is integrable with respect to $\mathbb P$, so
\begin{align*}
\int_\Omega Y(\omega)\,d\mathbb P(\omega)<\infty.
\end{align*}
Therefore $\operatorname{Var}(X)=\mathbb E[Y]$ is finite.
[/step]
[step:Expand the centered square and integrate term by term]
For every $\omega\in\Omega$, the algebraic identity for the real number $X(\omega)$ gives
\begin{align*}
(X(\omega)-m)^2=X(\omega)^2-2mX(\omega)+m^2.
\end{align*}
Each term on the right-hand side is integrable: $X^2$ is integrable by hypothesis, $X$ is integrable by the previous step, and the constant function $\omega\mapsto m^2$ is integrable because $\mathbb P(\Omega)=1$. Hence linearity of the Lebesgue integral yields
\begin{align*}
\operatorname{Var}(X)
&=\int_\Omega (X(\omega)-m)^2\,d\mathbb P(\omega)\\
&=\int_\Omega X(\omega)^2\,d\mathbb P(\omega)
-2m\int_\Omega X(\omega)\,d\mathbb P(\omega)
+\int_\Omega m^2\,d\mathbb P(\omega).
\end{align*}
[guided]
The point of this step is to replace the definition of variance, which involves the centered random variable $X-m$, by ordinary moments of $X$. We have already proved that the integrals involved are finite, so we may use linearity of the Lebesgue integral without encountering indeterminate expressions.
For every $\omega\in\Omega$, expanding the square in $\mathbb R$ gives
\begin{align*}
(X(\omega)-m)^2=X(\omega)^2-2mX(\omega)+m^2.
\end{align*}
We must check that each term can be integrated separately. The function $\omega\mapsto X(\omega)^2$ is integrable by the finite second moment hypothesis. The function $\omega\mapsto X(\omega)$ is integrable by the previous step. The constant function $\omega\mapsto m^2$ is integrable because
\begin{align*}
\int_\Omega m^2\,d\mathbb P(\omega)=m^2\mathbb P(\Omega)=m^2<\infty.
\end{align*}
Therefore linearity of the Lebesgue integral applies to the pointwise identity above, giving
\begin{align*}
\operatorname{Var}(X)
&=\int_\Omega (X(\omega)-m)^2\,d\mathbb P(\omega)\\
&=\int_\Omega X(\omega)^2\,d\mathbb P(\omega)
-2m\int_\Omega X(\omega)\,d\mathbb P(\omega)
+\int_\Omega m^2\,d\mathbb P(\omega).
\end{align*}
[/guided]
[/step]
[step:Use the probability normalization to obtain the computational formula]
By the definition of $m$ and the fact that $\mathbb P(\Omega)=1$,
\begin{align*}
\int_\Omega X(\omega)\,d\mathbb P(\omega)=m,
\qquad
\int_\Omega m^2\,d\mathbb P(\omega)=m^2\mathbb P(\Omega)=m^2.
\end{align*}
Substituting these identities into the expression from the previous step gives
\begin{align*}
\operatorname{Var}(X)
&=\mathbb E[X^2]-2m^2+m^2\\
&=\mathbb E[X^2]-m^2\\
&=\mathbb E[X^2]-(\mathbb E[X])^2.
\end{align*}
This proves the claimed computational formula for the variance.
[/step]