Let p>3 be a prime. For every a=1,2,...,p-1 let x(a) be the number in {1,...,p-1} such that ax(a) is congruent to 1 mod p (its inverse mod p). Let S be the sum of ax(a)^2 and let T be the sum of x(a) (in both cases sum over all a=1,2,...,p-1). Is it true that S-2T is always divisible by p^2? I noted this by computing for small values of p and I wonder if this is a known theorem or if there is a simple proof.

This follows from well-known results (although perhaps not in a totally straightforward way).

Let us write $x(a) = a^{-1} + p y(a)$, where $a^{-1}$ denotes the inverse of $a$ modulo $p^2$, and $y(a) \in \{0, \dots, p-1\}$. Then we find that $$ a x(a)^2 = a^{-1} + 2p y(a) \pmod{p^2} $$ so $$ S = \sum_{a = 1}^{p-1} a^{-1} + 2p \sum_{a = 1}^{p-1} y(a) \pmod{p^2} $$ while $$ T = \sum_{a = 1}^{p-1} a^{-1} + p \sum_{a = 1}^{p-1} y(a) \pmod{p^2}. $$

So $p^2 \mid S - 2T$ if and only if $\sum_{a = 1}^{p-1} a^{-1} = 0 \pmod {p^2}$, and this latter statement is a consequence of Wolstenholme's theorem.