We know that only when $X_{1}=X_{2}=1$ (both the $i$ th and the $j$ th persons get their hats back), $X_{i} \cdot X_{j}=1$. Otherwise, the product is 0 .
And the probability of getting $X_{i} \cdot X_{j}=1$ is $\frac{(n-2)!}{n!}=\frac{1}{n(n-1)}$.
Hence
$$
E\left(X_{i} \cdot X_{j}\right)=1 \times \frac{1}{n(n-1)}+0 \times\left(1-\frac{1}{n(n-1)}\right)=\frac{1}{n(n-1)}
$$