We start from the observation that for k=1,2,…,p we have
(k−1p−1)≡±1(modp).(1)
To see this, note that
p−1≡−1(modp),
p−2≡−2(modp),
⋮⋮
k≡−(p−k)(modp),
hence, multiplying,
(k−1)!(p−1)!≡±(p−k)!(modp)
and (1) follows. This can be written in an equivalent form
pk(kp)≡±1(modp),
which implies that
(kp)=p⋅kakp±1,
for some integer ak. Therefore, if p satisfies the given conditions, we have
p∣k=1∑p−1k2(akp±1)2,
or p∣∑k=1p−11/k2, where by 1/m we understand the unique integer 1≤l≤p−1 satisfying ml≡1(modp). Now observe that 1/k2≡(1/k)2(modp) and
k=1∑p−1k21≡k=1∑p−1k2=6p(p−1)(2p−1)(modp),
which is divisible by p if and only if p≥5.