The equality x2+7=x2+22+12+12+12 shows that n≤5. It remains to show that x2+7 is not a sum of four (or less) squares of polynomials with rational coefficients.
Suppose by way of contradiction that x2+7=f1(x)2+f2(x)2+f3(x)2+f4(x)2, where the coefficients of polynomials f1,f2,f3 and f4 are rational (some of these polynomials may be zero).
Clearly, the degrees of f1,f2,f3 and f4 are at most 1. Thus fi(x)=aix+bi for i=1,2,3,4 and some rationals a1,b1,a2,b2,a3,b3,a4,b4. It follows that x2+7=∑i=14(aix+bi)2 and hence
i=1∑4ai2=1,i=1∑4aibi=0,i=1∑4bi2=7.(1)
Let pi=ai+bi and qi=ai−bi for i=1,2,3,4. Then
i=1∑4pi2i=1∑4qi2 and i=1∑4piqi=i=1∑4ai2+2i=1∑4aibi+i=1∑4bi2=8,=i=1∑4ai2−2i=1∑4aibi+i=1∑4bi2=8=i=1∑4ai2−i=1∑4bi2=−6,
which means that there exist a solution in integers x1,y1,x2,y2,x3,y3,x4,y4 and m>0 of the system of equations
(i) i=1∑4xi2=8m2, (ii) i=1∑4yi2=8m2, (iii) i=1∑4xiyi=−6m2
We will show that such a solution does not exist.
Assume the contrary and consider a solution with minimal m. Note that if an integer x is odd then x2≡1(mod8). Otherwise (i.e., if x is even) we have x2≡0(mod8) or x2≡4(mod8). Hence, by (i), we get that x1,x2,x3 and x4 are even. Similarly, by (ii), we get that y1,y2,y3 and y4 are even. Thus the LHS of (iii) is divisible by 4 and m is also even. It follows that (2x1,2y1,2x2,2y2,2x3,2y3,2x4,2y4,2m) is a solution of the system of equations (i), (ii) and (iii), which contradicts the minimality of m.
Solution 2:
We prove that n≤4 is impossible. Define the numbers ai,bi for i=1,2,3,4 as in the previous solution.
By Euler's identity we have
(a12+a22+a32+a42)(b12+b22+b32+b42)=(a1b1+a2b2+a3b3+a4b4)2+(a1b2−a2b1+a3b4−a4b3)2+(a1b3−a3b1+a4b2−a2b4)2+(a1b4−a4b1+a2b3−a3b2)2
So, using the relations (1) from the Solution 1 we get that
7=(mm1)2+(mm2)2+(mm3)2(2)
where
mm1=a1b2−a2b1+a3b4−a4b3mm2=a1b3−a3b1+a4b2−a2b4mm3=a1b4−a4b1+a2b3−a3b2
and m1,m2,m3∈Z,m∈N.
Let m be a minimum positive integer number for which (2) holds. Then
8m2=m12+m22+m32+m2
As in the previous solution, we get that m1,m2,m3,m are all even numbers. Then (2m1,2m2,2m3,2m) is also a solution of (2) which contradicts the minimality of m. So, we have n≥5. The example with n=5 is already shown in Solution 1.