Solution (source code)

= Solution

Starting at $X$, the two possible two-step returns are $X\to X\to X$ and $X\to Y\to X$. They are <disjoint events>, with probabilities $1/4$ and $3/16$. Therefore
$$
\boxed{p_2=\frac14+\frac3{16}=\frac7{16}.}
$$
Each path probability uses the specified <Markov property> to multiply its successive transition probabilities.