Let $ \Delta $ be the discriminant of the equation
$$ \Delta=4\sum_{i=1}^{n+1}a_{i}^{2}-4a_{n+1}\sum_{i=1}^{n}a_{i} $$
We must have that $ \Delta \geq 0 $ which implies that $$ \sum_{i=1}^{n+1}a_{i}^{2} \geq a_{n+1}\sum_{i=1}^{n}a_{i} $$
Rewrite the last inequality as $$ a_{n+1}^{2}-a_{n+1}\sum_{i=1}^{n}a_{i}+\sum_{i=1}^{n}a_{i}^{2} \geq 0 $$
Since this must hold for any $ a_{n+1} \in \mathbb{R} $, we must have that the new discriminant $$\Delta '=\big(\sum_{i=1}^{n}a_{i}\big)^{2}-4\sum_{i=1}^{n}a_{i}^{2} \leq 0 $$
And the last inequality must hold for any real numbers $ a_{1}, \dots , a_{n} $.
We show that only $ n \in \{ 1,2,3,4\} $ satisfy this property.
So let $ n \geq 5 $and consider the example $ a_{i}=i $ $ \forall i \in \overline{1,n} $ . Then in this case, we must have that $$\Delta '=\big(\sum_{i=1}^{n}i\big)^{2}-4\sum_{i=1}^{n}i^{2}=\frac{n^{2}(n+1)^{2}}{4}-4\frac{n(n+1)(2n+1)}{6} \leq 0 $$
Dividing the last inequality by $ \frac{n(n+1)}{12} $, we see that we must have $$ 3n(n+1) -8(2n+1) \le 0 $$
Computation then shows that $$ n \in \big[\frac{13-\sqrt{265}}{6},\frac{13+\sqrt{265}}{6}\big] $$
But $ \sqrt{265}<17 $ so $ n<5 $.
Therefore the only remaining possibilities are $ n \in \{1,2,3,4\} $ and it is easily verified that all of them actually occur.
Indeed, for $ n=1 $, we must have that $ a_{1}^{2}-4a_{1}^{2} \leq 0 $ for any real number $ a_{1} $ which clearly holds.
For $ n=2$, we must have that $$ (a_{1}+a_{2})^{2}-4(a_{1}^{2}+a_{2}^{2})\leq 0 $$ which can be rewritten as $$ -(a_{1}-a_{2})^{2}-2(a_{1}^{2}+a_{2}^{2}) \leq 0 $$
which again holds true for any real numbers $ a_{1} $ and $ a_{2} $.
For $ n=3 $ we must have that $$(a_{1}+a_{2}+a_{3})^{2}-4(a_{1}^{2}+a_{2}^{2}+a_{3}^{2})\leq 0 $$
but by Cauchy-Scwarz, we have that $$(a_{1}+a_{2}+a_{3})^{2} \leq 3(a_{1}^{2}+a_{2}^{2}+a_{3}^{2}) $$ so clearly the inequality needed for $ n=3 $ holds as well.
Finally, for $n=4 $ what we need is exactly the Cauchy-Schwarz inequality $$(a_{1}+a_{2}+a_{3}+a_{4})^{2} \leq 4(a_{1}^{2}+a_{2}^{2}+a_{3}^{2}+a_{4}^{2}) $$
We conclude that $ n \in \{1,2,3,4\} $.