Example 11 Let real numbers $x, y, z$ satisfy
$$
\left\{\begin{array}{l}
x+y=z-1, \\
x y=z^{2}-7 z+14 .
\end{array}\right.
$$

Question: What is the maximum value of $x^{2}+y^{2}$? For what value of $z$ does $x^{2}+y^{2}$ achieve its maximum value?