It is straightforward to check that n=3,5 indeed satisfy the condition.
Below we prove that n≤5. Suppose a0,a1,…,ak satisfying the condition and from now on, ≡ works in modulo n. Since ai0=0 for some i0, so ai2≡c(i−i0) for some constant c. In particular, 1=12≡c(i1−i0) for some i1, and hence (i1−i0)(ai2−aj2)≡(i1−i0)(i−j)c≡i−j=0 unless i−j=0. Therefore, n must be a prime number, for if n=ab for some a≥b>1, then ai=(a+b)/2,aj=(a−b)/2 for some i=j and ai2−aj2≡0. In particular, {ai2} is the set of quadratic residues.
WLOG assume i0=k, otherwise, reverse the sequence so that i0=0. Since c=ai0+12, c is a quadratic residue, thus, {ai2},{c−1ai2},{−i0,i0+1,…,k−i0} are all the sets of quadratic residues and equivalent modulo n. If i0>0, then −1 is a quadratic residue, then we must have k=2i0 and since i0<k<n−i0, k cannot be a quadratic residue, thus 2 cannot be a quadratic residue. If i0=0, then k is a quadratic residue, and k<2k=n−1=2i0 is not a quadratic residue, thus 2 cannot be a quadratic residue. Therefore, we must have i0≤1, n=2k+1≤2(2i0)+1≤5.