The Riemann curvature tensor is defined in terms of the Levi-Civita connection
as
.
Its variation is
.
While the connection
is not a tensor, the difference
between two connections is, so we can take its covariant derivative
.
Solving this equation for
and substituting the result in
, all the
-like terms cancel, leaving only
.
Finally, the variation of the Ricci curvature tensor follows by contracting two indices, proving the identity
.