[guided]The purpose of this step is to make the word "reversible" precise. A state is an ordered pair $(M,E)$ for which $E$ divides $D-M^2$; this is why we first define
\begin{align*}
\mathcal{A}:=\{(M,E)\in\mathbb{Z}\times\mathbb{N}: E\mid D-M^2\}.
\end{align*}
For a state $(M,E)\in\mathcal{A}$, the number
\begin{align*}
\delta(M,E)=\frac{D-M^2}{E}
\end{align*}
is the modulus of the predecessor state. The predecessor map $P:\mathcal{A}\to\mathbb{Z}\times\mathbb{N}$ defined by
\begin{align*}
P(M,E):=(r,\delta(M,E))
\end{align*}
chooses the unique integer $r$ satisfying
\begin{align*}
a_0-\delta(M,E)<r\leq a_0,
\qquad
r\equiv -M \pmod{\delta(M,E)}.
\end{align*}
The uniqueness is exactly the elementary residue fact that any interval of length $q\in\mathbb{N}$ contains one representative of each residue class modulo $q$ when the interval is half-open of the form $(b-q,b]$.
For an actual continued-fraction transition, the recurrence gives
\begin{align*}
d_{n+1}=\frac{D-m_{n+1}^2}{d_n},
\qquad
m_n\equiv -m_{n+1}\pmod{d_n}.
\end{align*}
The reduced inequality from the previous step says
\begin{align*}
a_0-d_n<m_n\leq a_0.
\end{align*}
Thus $m_n$ is precisely the representative selected by the definition of $P$, and therefore
\begin{align*}
P(m_{n+1},d_{n+1})=(m_n,d_n)
\end{align*}
for every $n\geq 1$.
Now define
\begin{align*}
R_i:=(m_{\ell-i},d_{\ell-i}),
\qquad
S_i:=(m_{i+1},d_i)
\end{align*}
for $0\leq i\leq \ell-1$. The terminal computation gives
\begin{align*}
R_0=(m_\ell,d_\ell)=(a_0,1),
\end{align*}
and the initial recurrence gives
\begin{align*}
S_0=(m_1,d_0)=(a_0,1).
\end{align*}
So $R_0=S_0$.
Assume $R_i=S_i$ for some $0\leq i\leq \ell-2$. On the reversed side, $R_i$ is an actual state, so the predecessor rule gives
\begin{align*}
P(R_i)=P(m_{\ell-i},d_{\ell-i})=(m_{\ell-i-1},d_{\ell-i-1})=R_{i+1}.
\end{align*}
For the shifted forward side, we must not merely assert the same formula, because $S_i=(m_{i+1},d_i)$ is indexed differently from the usual state $(m_{i+1},d_{i+1})$. We compute it. Since $R_i=S_i$ and $R_i\in\mathcal{A}$, the pair $S_i$ lies in $\mathcal{A}$. Moreover
\begin{align*}
\delta(m_{i+1},d_i)=\frac{D-m_{i+1}^2}{d_i}=d_{i+1}.
\end{align*}
The next recurrence is
\begin{align*}
m_{i+2}=d_{i+1}a_{i+1}-m_{i+1},
\end{align*}
which gives
\begin{align*}
m_{i+2}\equiv -m_{i+1}\pmod{d_{i+1}}.
\end{align*}
The reduced inequalities at index $i+2$ give
\begin{align*}
a_0-d_{i+1}<m_{i+2}\leq a_0.
\end{align*}
Thus $m_{i+2}$ is the unique representative selected by $P$, and hence
\begin{align*}
P(S_i)=P(m_{i+1},d_i)=(m_{i+2},d_{i+1})=S_{i+1}.
\end{align*}
Since $R_i=S_i$ as ordered pairs and $P$ is a function, $P(R_i)=P(S_i)$. Combining the two computations gives
\begin{align*}
R_{i+1}=S_{i+1}.
\end{align*}
Induction proves
\begin{align*}
(m_{\ell-i},d_{\ell-i})=(m_{i+1},d_i)
\end{align*}
for every $0\leq i\leq \ell-1$.[/guided]