We are going to assume that \(a \gt 1\). If \(a\) is odd, then \(a^n\) is odd, so \(a^n + 1\) would be even and therefore can't be prime. Which means \(a^n + 1\) being prime means \(a\) is even:
$$ a^n + 1 \in \mathbb{P} \implies 2 | a $$
Now suppose \(n\) is not a power of 2. If \(n \ne 2^k\), then according to the Fundamental Theorem of Arithmetic, there must be an odd prime (let's call it \(s\)) that divides \(n\), so \(n = rs\) for some integer \(r\). Also, according to this lemma:
$$ (i - j) | (i^m - j^m) $$
Let \(i = a^r\), \(j=-1\) and \(m=s\):
$$ (a^r + 1) | (a^{rs} + 1) $$$$ (a^r + 1) | (a^n + 1) $$
If \(a \gt 1\) and \((a^r + 1) | (a^n + 1)\), then \((a^n + 1)\) cannot be prime, which means:
$$ n \ne 2^k \implies a^n + 1 \notin \mathbb{P}$$
The contrapositive of this is:
$$ a^n + 1 \in \mathbb{P} \implies n = 2^k $$