Let $n\in \mathbb N$ be a natural number, $x\_1,\cdots.x\_n$ be formal variables. Consider the following $n\times n$-matrix $M\_n:=diag\{x\_1^2+\cdots+x\_n^2,\cdots,x\_1^2+\cdots+x\_n^2\}$, can we find a solution $A=(a\_{ij})$ such that 


* (Square root): $A^2=M\_n$.
* (Polynomial): $a\_{ij}\in \mathbb F[x\_1,\cdots,x\_n]$ be a polynomial, where $\mathbb F$ is a number field such as $\mathbb Q, \mathbb R$ or $\mathbb C$.(However this condition is not essential and we may use formal series $\mathbb F[[x\_1,\cdots,x\_n]]$.)


Of course, we do not order $A$ is diagonal. Moreover, as Will pointed out there is no solution for odd cases when $n\geq3$ since the determinant is not a square. For $n=2$ we have an example 
$$
\begin{pmatrix}
x\_1^2+x\_2^2 &\\
&x\_1^2+x\_2^2
\end{pmatrix}=\begin{pmatrix}\pm x\_1 & x\_2\\
x\_2& \mp x\_1\end{pmatrix}^2
.$$



Finding the square root of a special matrix
As Will noted, if $n>1$, one must have $n$ even for there to be any solutions. (This holds even if the $a\_{ij}$ are allowed to be formal power series in the $x\_i$, since ${x\_1}^2+\cdots+{x\_n}^2$ is not a square even in this larger ring when $n>1$.) (Of course, the $n=1$ case is trivial, so we can set that aside.)


Conversely, when $n=2m$, there is always a solution; just take
$$
A = \begin{pmatrix}0\_m & I\_m \\ ({x\_1}^2+\cdots+{x\_n}^2)I\_m & 0\_m\end{pmatrix}.
$$


However, I suspect that the OP actually wanted $A = A(x)$ to satisfy $A(0)=0\_n$, and this is much more restrictive. 


Thus, assume that $A(x)$ has no constant term, i.e., $A(0)=0\_n$. Then the problem comes down to a question about Clifford algebras: Write $A = A^i\,x\_i + R\_2(x)$ where $R\_2(x)$ vanishes to order $2$ in $x$ and the $A^i$ are $n$-by-$n$ matrices with entries in $\mathbb{F}$. Then the equation $A^2=M = ({x\_1}^2+\cdots+{x\_n}^2)I\_n$ implies, in particular, that $A^iA^j+A^jA^i = 2\delta^{ij}I\_n$. These are the defining equations of a Clifford algebra over $\mathbb{F}$. 


For simplicity, take $\mathbb{F}=\mathbb{C}$. The algebra $\mathbb{C}\ell\_n$ generated over $\mathbb{C}$ by $n$ generators $J^i$ subject only to to the relations $J^iJ^j+J^jJ^i = 2\delta^{ij} 1$, is known to have dimension $2^n$ and, since $n$ is even, it is also known to be isomorphic to $M\_N(\mathbb{C})$, the algebra of $N$-by-$N$ matrices with complex entries, where $N = 2^{n/2}$. (See any book on Clifford algebras or simply consult the Wikipedia page on Clifford algebras.) 


The assignment $J^i\mapsto A^i$ induces a homomorphism $a:\mathbb{C}\ell\_n (= M\_N(\mathbb{C}))\to M\_n(\mathbb{C})$ of algebras with unit, and, by the usual theory of matrix algebras, this can only happen if $N$ divides $n$, i.e., if $2^{n/2}$ divides $n$. Of course, this only holds when $n=2$ and $n=4$. 


Conversely, when $n=2$ or $n=4$, the unital algebra $\mathbb{C}\ell\_n$ is isomorphic to $M\_n(\mathbb{C})$, so the desired $A^i$ do exist satisfying $A^iA^j+A^jA^i = 2\delta^{ij}I\_n$ (and they are unique up to conjugation), and we can simply take $A = A^i\,x\_i$ (i.e., $R\_2(x)=0$) to get a solution. For example, when $n=4$, one could take
$$
A = \begin{pmatrix}0&0&x\_1+i\,x\_2& x\_3+i\,x\_4\\0&0&-(x\_3-i\,x\_4)&x\_1-i\,x\_2\\
x\_1-i\,x\_2& -(x\_3+i\,x\_4)&0&0\\x\_3-i\,x\_4&x\_1+i\,x\_2&0&0\end{pmatrix}.
$$
(Of course, there are also many solutions with $R\_2$ not vanishing identically.)


Obviously, if a solution of this kind existed with $\mathbb{F}= \mathbb{Q}$ or $\mathbb{R}$, then we could complexify and get a solution with $\mathbb{F}=\mathbb{C}$, so the only dimensions in which solutions of this kind could possibly exist are $n=2$ or $n=4$. The case $n=2$ clearly does work in these cases, and, indeed, the OP gives a solution. Unfortunately, when $\mathbb{F}=\mathbb{Q}$ or $\mathbb{R}$, the case $n=4$ is impossible, because, when the ground field is $\mathbb{R}$, the algebra generated by the $J^i$ subject to the above relations is isomorphic to $M\_2(\mathbb{H})$, and this algebra does not have a nontrivial homomorphism to $M\_4(\mathbb{R})$.


