Suppose that $u$ is a harmonic function on $\mathbb{R}^n$. Then by the mean-value property we know that for each $x \in \mathbb{R}^n$ and $r>0$ we have that
$$
u(x) = \frac{1}{\omega_n r^{n}} \int_{ B(x,r)} u(y) dy
$$
where $\omega_n$ is the volume of the unit ball in $\mathbb{R}^n$. From this and Cauchy-Schwarz we get the estimate
$$
|u(x)| \le \frac{1}{\omega_n r^n} \int_{B(x,r)} |u(y)| dy \le \frac{1}{\omega_n r^n} \left( \int_{B(x,r)} |u(y)|^2 dy \right)^{1/2} |B(x,r)|^{1/2} \\
=\frac{1}{\sqrt{\omega_n} r^{n/2}} \left( \int_{B(x,r)} |u(y)|^2 dy \right)^{1/2}
$$
Now, if $u$ is such that
$$
\int_{\mathbb{R}^n} | u(y)|^2 dy = M^2 < \infty,
$$
then we in turn find that
$$
|u(x)| \le \frac{1}{\sqrt{\omega_n} r^{n/2}} \left( \int_{B(x,r)} |u(y)|^2 dy \right)^{1/2} \le \frac{1}{\sqrt{\omega_n} r^{n/2}} \left( \int_{\mathbb{R}^n} |u(y)|^2 dy \right)^{1/2} = \frac{M}{\sqrt{\omega_n} r^{n/2}}.
$$
Then for any fixed $x \in \mathbb{R}^n$ we can send $r \to \infty$ to get that
$$
|u(x)| \le \lim_{r \to \infty}\frac{M}{\sqrt{\omega_n} r^{n/2}} =0,
$$
and hence we find that $u(x) =0$ for all $x$. Thus the only harmonic function that is square-integrable over all of $\mathbb{R}^n$ is $0$.
Having established this, we can now answer your question. Suppose now that $u$ is harmonic on $\mathbb{R}^n$ and $D^2 u$ is square-integrable. Since $u$ is harmonic, it's smooth, and so we can apply arbitrarily many derivatives to the PDE $\Delta u =0$. In particular we find that if $|\alpha|=2$ then
$$
0 = \partial^\alpha \Delta u = \Delta \partial^\alpha u,
$$
which means that all of the second-order partial derivatives are also harmonic. Since
$$
\int_{\mathbb{R}^n} |\partial^\alpha u |^2 \le \int_{\mathbb{R}^n} |D^2 u |^2 < \infty
$$
we find that $\partial^\alpha u$ is a harmonic function that is square-integrable. By the above analysis we then know that $\partial^\alpha u =0$ for all multi-indices with $|\alpha |=2$. In other words, we know that $D^2 u =0$, and so basic calculus tells us that $u$ is linear, i.e. $u(x) = a + b \cdot x$ for some $a \in \mathbb{R}$ and $b\in \mathbb{R}^n$. It turns out that all such functions are trivially harmonic.
Thus a harmonic functions has $D^2 u$ square integrable if and only if it's linear.