Let $u\in W^{1,p}(U)$ such that $Du=0$ a.e. on $U$. I have to prove that $u$ is constant a.e. on $U$.
Take $(\rho_{\varepsilon})_{\varepsilon>0}$ mollifiers. I know that $D(u\ast\rho_{\varepsilon})=Du\ast\rho_{\varepsilon}$, so $u\ast\rho_{\varepsilon}(x)=c $ for every $x\in U$, since it is a smooth function.
How can I conclude?
By (well-known) properties of mollification, $u*\rho_\epsilon\rightarrow u$ in $W^{1,p}$ as $\varepsilon \rightarrow 0$. Since $u*\rho_\epsilon = c_\varepsilon$ is a constant for each $\varepsilon$, and $u*\rho_\epsilon\rightarrow u$, $u$ is the limit of constant functions and must be constant as well (e.g. because convergence in $L^p$ implies convergence a.e.).
you should note that
i) this is only true for each connected component of $U$
ii) strictly speaking $u*\rho_\epsilon$ is only defined on $U_\varepsilon = \{x\in U: d(x,\mathbb{R}^n\backslash U)>\varepsilon\}$, so you first get the result for any such domain, but then it it true for $U$ if $\varepsilon$ tends to $0$.