For an harmonic map $u$ from a domain $U\subset\X$ in an $\RCD(K,N)$ space $\X$ to a $\CAT(0)$ space $\Y$ we prove the Lipschitz estimate
\[
\Lip(u\restr B)\leq \frac {C(K^-R^2,N)}r\inf_{\o\in\Y}\,\sqrt{\fint_{2B}\sfd_\Y^2(u(\cdot),\o)\,\d\mm},\qquad\forall 2B\subset U,
\]
where $r\in(0,R)$ is the radius of $B$. This is obtained by combining classical Moser's iteration, a Bochner-type inequality that we derive (guided by recent works of Zhang-Zhu) together with a reverse Poincar\'e inequality that is also established here. A direct consequence of our estimate is a Lioville-Yau type theorem in the case $K=0$.
Among the ingredients we develop for the proof, a variational principle valid in general $\RCD$ spaces is particularly relevant. It can be roughly stated as: if $(\X,\sfd,\mm)$ is $\RCD(K,\infty)$ and $f\in C_b(\X)$ is so that $\Delta f\leq C$ for some constant $C>0$, then for every $t>0$ and $\mm$-a.e.\ $x\in\X$ there is a unique minimizer $F_t(x)$ for
$
y\ \mapsto\ f(y)+\frac{\sfd^2(x,y)}{2t}
$
and the map $F_t$ satisfies
\[
(F_t)_*\mm\leq e^{t(C+2K^-\osc(f))}\mm,\qquad\text{where}\qquad\osc(f):=\sup f-\inf f.
\]
Here existence is in place without any sort of compactness assumption and uniqueness should be intended in a sense analogue to that in place for Regular Lagrangian Flows and Optimal Maps (and is related to both these concepts).
Finally, we also obtain a Rademacher-type result for Lipschitz maps between spaces as above.