Let's look at the general case.
 $$aX^2+bY^2=cZ^2+N$$
 When the coefficients of this equation are not represented in the form of squares. Then a funny pattern emerges. If we know some solution to the equation and we know any solution to the Pell equation. Then we can always construct the following solution to this equation.
 $$\left\{\!\begin{aligned} & ax^2+bY^2=cz^2+N \\ & cp^2-as^2=1 \end{aligned}\right. $$
 Formally, the relationship between the solvability of the Lagrange equation in general and the solvability of the equivalent Pell equation is obtained.
 Numbers can have any signs.
 $$f=\sqrt{ac(sz+px)^2+by^2-N}$$
 $$\left\{\!\begin{aligned} & X=cxp^2+fs+czps \\ & Z=axps+pf+azs^2 \end{aligned}\right. $$
 $$\left\{\!\begin{aligned} & X=cxp^2-2czps+axs^2 \\ & Z=czp^2-2axps+azs^2 \end{aligned}\right. $$
 Solutions to the general equation.
 $$cp^2-as^2=1$$
 They are found using solutions.
 $$\left\{\!\begin{aligned} & q^2-can^2=1 \\ & ck^2-at^2=1 \end{aligned}\right.$$
 $$\left\{\!\begin{aligned} & p=qk+atn \\ & s=qt+cnk \end{aligned}\right.$$
 Consider the example mentioned in the question.
 $$8X^2+13Y^2=Z^2-4$$
 $X=1 ; Y=1 ; Z=5 $
 $a=8 ; b=13 ; c=1$
 Solutions to the Pell equation $p^2-8s^2=1$
 $(p ; s) - (3 ; 1)$
 $$\left\{\!\begin{aligned} & P=3p+8s \\ & S=3s+p \end{aligned}\right. $$
 We substitute it and get it. The first gives $(x;Y;z) - (1597;1;4517)$, the second $(x;Y;z)-(443;1;1253)$
 For any value of $(X,Y)$, an infinite number of solutions are obtained.