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})$.

orthogonal design matrix. One reference is amazon.com/exec/obidos/ASIN/0824767748. $\endgroup$ – Richard Stanley Jun 15 '15 at 13:42