5. Given a pyramid $S-ABCD$ inscribed in a sphere with the base being a rectangle $ABCD$, and $SA=4, SB=8, SD=7$, $\angle SAC=\angle SBC=\angle SDC$. Then the length of $BD$ is
5. $B D=9$.

As shown in the figure, $\because \angle S A C=\angle S B C=\angle S D C$,
$$
\therefore \frac{S C}{\sin \angle S A C}=\frac{S C}{\sin \angle S B C}=\frac{S C}{\sin \angle S D C} \text {. }
$$

Therefore, the circumcircles of $\triangle S A C$,
$\triangle S B C, \triangle S D C$ have equal diameters, meaning the circles formed by the intersection of the sphere with the planes $S A C$, plane $S B C$,
plane $S D C$ are equal.
The plane passing through the midpoint $O$ of $S C$ and perpendicular to $S C$ intersects $S A C, S B C, S D C$ at the midpoints of the arcs $A^{\prime} 、 B^{\prime} 、 D^{\prime}$, and $O A^{\prime}=O B^{\prime}=O D^{\prime}$, thus, $O$ is the circumcenter of $\triangle A^{\prime} B^{\prime} C^{\prime}$. Hence, $S C$ is the diameter of the sphere, $O$ is the center of the sphere, and $\angle \mathrm{SAC}=\angle \mathrm{SBC}=\angle \mathrm{SDC}=90^{\circ}$.
Let $B D=A C=x, A B=y, B C=z$. Then
$$
S C^{2}=x^{2}+4^{2}=y^{2}+7^{2}=z^{2}+8^{2} \text {, }
$$

which simplifies to $2\left(x^{2}+16\right)=\left(y^{2}+49\right)+\left(z^{2}+64\right)$
$$
=x^{2}+49+64 \text {. }
$$

Solving this, we get $x=9$, i.e., $B D=9$.