Consider the following derivation in David Vanderbilt's book "Berry Phases in Electronic Structure Theory - Electric Polarization, Orbital Magnetization and Topological Insulators" (2018, Cambridge University Press (page 100).
The wave function for the adiabatic approach is as follows: \begin{equation} |\psi(t)\rangle=e^{i\phi(\lambda(t))}e^{-i\gamma(t)}|n(t)\rangle \tag{1}\label{1} \end{equation}
where $e^{i\phi(\lambda(t))}$ is the geometric phase or Berry phase and $e^{-i\gamma(t)}$ is dynamic phase.
Berry phase has the following mathematical expression: \begin{equation} \phi(t)=\int_{\lambda(0)}^{\lambda(t)}A_n(\lambda)d\lambda \tag{2}\label{2} \end{equation} where $A_n$ is Berry connection.
Dynamic phase has the following mathematical expression: \begin{equation} \gamma(t)=\frac{1}{\hbar}\int_{0}^{t}E_n(t')dt' \tag{3}\label{3} \end{equation}
Expanding equation number (1) with first order $\lambda$ terms:
\begin{equation} |\psi(t)\rangle=e^{i\phi(\lambda(t))}e^{-i\gamma(t)}\big[|n(\lambda)\rangle+\dot{\lambda}|\delta n(t)\rangle\big] \tag{4}\label{4} \end{equation}
Equation (4) solves the time-dependent Schrödinger equation to order zero in $\dot{\lambda}$, but we now require that it should also do so at first order.
For this purpose we can discard terms that scale like $\ddot{\lambda}$ or $\lambda^2$. You get: \begin{equation} (E_n-H_{\lambda})|\delta n\rangle=-i\hbar (\partial_{\lambda}+iA_n)|n\rangle. \tag{5}\label{5} \end{equation}
which can also be written like:
$$\begin{equation} (E_n-H_{\lambda})|\delta n\rangle=-i\hbar \mathcal{Q}_{n}|\partial_{\lambda}n\rangle \tag{6}\label{6} \end{equation} $$
where $\mathcal{Q}_n=1-|n\rangle\langle n|$.
How did they get equation (5) and (6) from equation (4)?