Conjecture: When $n \gt 2$ is an even number, $n\pm 1$ is a twin prime pair iff there exists a nontrivial solution of $X^{(n-2)n} = 1 \pmod {n^2 - 1}$.
Proof:
To see this suppose $n \pm 1 \in \Bbb{Z}$ are twin primes. Then by Euler's totient theorem $X^{n-2} = 1 \pmod {n-1}$ and $X^{n} = 1 \pmod {n+1}$. So that by the Chinese Remainder theorem those two equations multiply into $X^{(n-2)n} = 1 \pmod {n^2 -1}$.
Conversely, suppose that the even number $n \gt 2$ is such that a solution $X$ exists to the equation $X^{n(n-2)} = 1 \pmod {n^2-1}$.
Since $n$ is even $n \pm 1$ must be a coprime pair of integers: Fixing the coprime error. $d | n \pm 1 \implies n-1 = n+1 \pmod d \implies -1 = 1 \implies d = 2$ but $n$ is even, so $dx = n + 1 \implies 1 = 0 \pmod 2$. Done.
Since $n \pm 1$ are coprime now, we can use the reverse isomorphism from the Chinese Remainder Theorem and break into two equations: $X^{(n-2)n} = 1 \pmod {n\pm 1}$.
We feel the need to appeal to Euler's totient function. We know that the multiplicative group of the ring $\Bbb{Z}/(m)$ must have order $\phi(m)$ and that there is a formula for it: $\phi(m) = m \prod_{p |m}p^{e-1}(1 - 1/p)$ where $e$ in the formula is the max exponent of the prime $p$ dividing $m$.
Let $m = n^2 -1$. And $R = \Bbb{Z}/(m)$. Clearly $\phi(m) = |R^{\times}| \lt |R|$. Since in our smaller rings $X^{n(n-2)} = 1$, we have that
Apparently this conjecture is false. See below.