Given any number $\lambda$ and any function $u\in H^{1}$, let $\tilde u=\max(u,\lambda)$. I claim that $\tilde u\in H^1$ and $D(\tilde u)\le D(u)$.
Indeed, $\tilde u:=\max(u,\lambda)$ is ACL (absolutely continuous on almost every line), because $u$ is. Thus, the pointwise derivatives $\tilde u_{x_i}$ exist a.e., and represent the weak derivatives of $u$. The definition of pointwise derivative tells us that at every point where $\tilde u_{x_i}$ exists, either $\tilde u_{x_i}=0$ or $\tilde u_{x_i}=u_{x_i}$ holds. Therefore, $|\tilde u_{x_i}|\le |u_{x_i}|$ a.e., which implies $D(\tilde u)\le D(u)$.
The same holds for $\min$ instead of $\max$, by symmetry or by repeating the above reasoning.
Finally, let $u_0$ be the unique minimizer of Dirichlet energy under the boundary condition $u_{\partial D}=f$ and the obstacle condition $f\ge \varphi$. (Uniqueness follows from the strict convexity of the energy functional.) Let $\lambda_1=\inf f$ and $\lambda_2=\max (\sup f,\sup\varphi)$. Observe that $\tilde u:=\max(u,\lambda_1)$ also satisfies the boundary and obstacle conditions. By the above we have $D(\tilde u)\le D(u)$. Since $u$ is the unique minimizer, $\tilde u=u$ a.e. This means precisely that $u\ge \lambda_1$ a.e. Having established this, repeat the argument with $\tilde u:=\min(u,\lambda_2)$ to conclude that $u\le \lambda_2$ a.e.