One can easily show that if $p$ is a prime that does not divide $a$, then $a^{p(p-1)}\equiv 1 \pmod{p^2}$.
However, my question is: If instead of $p$ being a prime, it were a pseudoprime to the base $a$, would the result still be valid? Moreover, in general, for what (if any) composite numbers $p$ would the above result be valid?
My interest in this question stems from a study of the extended Lucas sequences (with sequences of the form $a^{n} - 1$ being special cases of them.)
Thank you.