Let $\mathcal{F}$ be an abelian sheaf on $\mathcal{X}_\etale$ (resp.\ $\mathcal{X}_{fppf}$). We first show that the canonical (base change) map $$ g^{-1} Rf_*\mathcal{F} \longrightarrow Rf'_* (g')^{-1}\mathcal{F} $$ is an isomorphism. To do this let $y$ be an object of $\mathcal{Y}_{lisse,\etale}$ (resp.\ $\mathcal{Y}_{flat,fppf}$). Say $y$ lies over the scheme $V$ such that $y : V \to \mathcal{Y}$ is smooth (resp.\ flat). Since $g^{-1}$ is the restriction we find that $$ \left(g^{-1}R^pf_*\mathcal{F}\right)(y) = H^p_\tau(V \times_{y, \mathcal{Y}} \mathcal{X},\ \text{pr}^{-1}\mathcal{F}) $$ where $\tau = \etale$ (resp.\ $\tau = fppf$), see  Sheaves on Stacks, Lemma \ref{stacks-sheaves-lemma-pushforward-restriction}. By Cohomology of Stacks, Equation (\ref{stacks-cohomology-equation-pushforward-lisse-etale})  for any sheaf $\mathcal{H}$ on $\mathcal{X}_{lisse,\etale}$ (resp.\ $\mathcal{X}_{flat,fppf}$) $$ f'_*\mathcal{H}(y) = \Gamma((V \times_{y, \mathcal{Y}} \mathcal{X})', \ (\text{pr}')^{-1}\mathcal{H}) $$ An object of $(V \times_{y, \mathcal{Y}} \mathcal{X})'$ can be seen as a pair $(x, \varphi)$ where $x$ is an object of $\mathcal{X}_{lisse,\etale}$ (resp.\ $\mathcal{X}_{flat,fppf}$) and $\varphi : f(x) \to y$ is a morphism in $\mathcal{Y}$. We can also think of $\varphi$ as a section of $(f')^{-1}h_y$ over $x$. Thus $(V \times_\mathcal{Y} \mathcal{X})'$ is the localization of the site $\mathcal{X}_{lisse,\etale}$ (resp. $\mathcal{X}_{flat,fppf}$) at the sheaf of sets $(f')^{-1}h_y$, see Sites, Lemma \ref{sites-lemma-localize-topos-site}. The morphism $$ \text{pr}' : (V \times_{y, \mathcal{Y}} \mathcal{X})' \to \mathcal{X}_{lisse,\etale} \ (\text{resp. } \text{pr}' : (V \times_{y, \mathcal{Y}} \mathcal{X})' \to \mathcal{X}_{flat,fppf}) $$ is the localization morphism. In particular, the pullback $(\text{pr}')^{-1}$ preserves injective abelian sheaves, see Cohomology on Sites, Lemma \ref{sites-cohomology-lemma-cohomology-on-sheaf-sets}. At this point exactly the same argument as in Sheaves on Stacks, Lemma \ref{stacks-sheaves-lemma-pushforward-restriction} shows that \begin{equation} \label{equation-higher-direct-image-lisse-etale} R^pf'_*\mathcal{H}(y) = H^p_\tau((V \times_{y, \mathcal{Y}} \mathcal{X})', \ (\text{pr}')^{-1}\mathcal{H}) \end{equation} where $\tau = \etale$ (resp.\ $\tau = fppf$). Since $(g')^{-1}$ is given by restriction we conclude that $$ \left(R^pf'_*(g')^*\mathcal{F}\right)(y) = H^p_\tau((V \times_{y, \mathcal{Y}} \mathcal{X})', \ \text{pr}^{-1}\mathcal{F}|_{(V \times_{y, \mathcal{Y}} \mathcal{X})'}) $$ Finally, we can apply Sheaves on Stacks, Lemma \ref{stacks-sheaves-lemma-cohomology-on-subcategory} to see that $$ H^p_\tau((V \times_{y, \mathcal{Y}} \mathcal{X})', \ \text{pr}^{-1}\mathcal{F}|_{(V \times_{y, \mathcal{Y}} \mathcal{X})'}) = H^p_\tau(V \times_{y, \mathcal{Y}} \mathcal{X},\ \text{pr}^{-1}\mathcal{F}) $$ are equal as desired; although we omit the verification of the assumptions of the lemma we note that the fact that $V \to \mathcal{Y}$ is smooth (resp.\ flat) is used to verify the second condition. \medskip\noindent The rest of the proof is formal. Since cohomology of abelian groups and sheaves of modules agree we also conclude that  $g^{-1} Rf_*\mathcal{F} = Rf'_* (g')^{-1}\mathcal{F}$ when $\mathcal{F}$ is a sheaf of modules on $\mathcal{X}_\etale$ (resp.\ $\mathcal{X}_{fppf}$). \medskip\noindent Next we show that for $\mathcal{G}$ (either sheaf of modules or abelian groups) on $\mathcal{Y}_{lisse,\etale}$ (resp.\ $\mathcal{Y}_{flat,fppf}$) the canonical map $$ L(g')_!(f')^{-1}\mathcal{G} \to f^{-1}Lg_!\mathcal{G} $$ is an isomorphism. To see this it is enough to prove for any injective sheaf $\mathcal{I}$ on $\mathcal{X}_\etale$ (resp.\ $\mathcal{X}_{fppf}$) that the induced map $$ \Hom(L(g')_!(f')^{-1}\mathcal{G}, \mathcal{I}[n]) \leftarrow \Hom(f^{-1}Lg_!\mathcal{G}, \mathcal{I}[n]) $$ is an isomorphism for all $n \in \mathbf{Z}$. (Hom's taken in suitable derived categories.) By the adjointness of $f^{-1}$ and $Rf_*$, the adjointness of $Lg_!$ and $g^{-1}$, and their ``primed'' versions this follows from the isomorphism $g^{-1} Rf_*\mathcal{I} \to Rf'_* (g')^{-1}\mathcal{I}$ proved above. \medskip\noindent In the case of a bounded complex $\mathcal{G}^\bullet$ (of modules or abelian groups) on $\mathcal{Y}_{lisse,\etale}$ (resp.\ $\mathcal{Y}_{fppf}$) the canonical map \begin{equation} \label{equation-to-show} L(g')_!(f')^{-1}\mathcal{G}^\bullet \to f^{-1}Lg_!\mathcal{G}^\bullet \end{equation} is an isomorphism as follows from the case of a sheaf by the usual arguments involving truncations and the fact that the functors $L(g')_!(f')^{-1}$ and $f^{-1}Lg_!$ are exact functors of triangulated categories. \medskip\noindent Suppose that $\mathcal{G}^\bullet$ is a bounded above complex (of modules or abelian groups) on $\mathcal{Y}_{lisse,\etale}$ (resp.\ $\mathcal{Y}_{fppf}$). The canonical map (\ref{equation-to-show}) is an isomorphism because we can use the stupid truncations $\sigma_{\geq -n}$ (see Homology, Section \ref{homology-section-truncations}) to write $\mathcal{G}^\bullet$ as a colimit $\mathcal{G}^\bullet = \colim \mathcal{G}_n^\bullet$ of bounded complexes. This gives a distinguished triangle $$ \bigoplus\nolimits_{n \geq 1} \mathcal{G}_n^\bullet \to \bigoplus\nolimits_{n \geq 1} \mathcal{G}_n^\bullet \to \mathcal{G}^\bullet \to \ldots $$ and each of the functors $L(g')_!$, $(f')^{-1}$, $f^{-1}$, $Lg_!$ commutes with direct sums (of complexes). \medskip\noindent If $\mathcal{G}^\bullet$ is an arbitrary complex (of modules or abelian groups) on $\mathcal{Y}_{lisse,\etale}$ (resp.\ $\mathcal{Y}_{fppf}$) then we use the canonical truncations $\tau_{\leq n}$ (see Homology, Section \ref{homology-section-truncations}) to write $\mathcal{G}^\bullet$ as a colimit of bounded above complexes and we repeat the argument of the paragraph above. \medskip\noindent Finally, by the adjointness of $f^{-1}$ and $Rf_*$, the adjointness of $Lg_!$ and $g^{-1}$, and their ``primed'' versions we conclude that the first identity of the lemma follows from the second in full generality.