Under what conditions is $M_n(R)$ commutative? 
Let $R$ be a ring and $n$ a positive integer. Under what conditions is $M_n(R)$
commutative?

I know that if every ring with a prime number of elements is commutative. Thus, if the number of elements of $R$ is prime, then $M_n(R)$ is a commutative ring. I think this is not a complete answer, in this question they tell me something about what a complete answer would look like, but they don't give any indication of how to prove it. How could this result be showed?
 A: It is clear that if $n=1$ and $R$ is commutative, then $M_n(R)$ is commutative: it is just isomorphic to $R$.
If you assume rings must have a $1$, then the statement as given in the other post suffices: $M_n(R)$ is commutative if and only if $n=1$ and $R$ is commutative, or $R$ is the zero ring. If you allow rings without a $1$, then there is another situation in which the matrix ring is commutative: when $R$ is a zero-multiplication ring (that is, $ab=0$ for all $a,b\in R$).
Indeed, for such a ring (a ring in which the product is always zero; this includes the zero ring), let $A=(a_{ij})$ and $B=(b_{ij})$ be any two matrices. Then $AB=C=(c_{ij})$, and $BA=D=(d_{ij})$, where
$$\begin{align*}
c_{ij} &= \sum_{k=1}^n a_{ik}b_{kj} = 0,\\
d_{ij} &= \sum_{k=1}^n b_{ik}a_{kj} = 0
\end{align*}$$
so that $C=D$, that is, $AB=BA$, regardless of the value of $n$. Note that such a ring is either the zero ring, or else it has no unity. In any case, it is commutative.
Suppose that $R$ is not the trivial ring, and is not a zero-multiplication ring, and $n\gt 1$. Let $a,b\in R$ be such that $ab\neq 0$. Consider
$$A=\left(\begin{array}{cccc}
0&a&\cdots &0\\
0&0&\cdots &0\\
\vdots &\vdots &\ddots & \vdots\\
0&0&\cdots &0\\
\end{array}\right),\qquad B=\left(\begin{array}{cccc}
0 & 0 & \cdots & 0\\
b & 0 & \cdots & 0\\
\vdots & \vdots & \ddots & \vdots \\
0 & 0 & \cdots & 0
\end{array}\right).$$
That is, $A=(a_{ij})$ and $B=(b_{ij})$, where
$$a_{ij} = \left\{\begin{array}{ll}
a &\text{if }i=1, j=2;\\
0 & \text{otherwise.}
\end{array}\right.\qquad\text{and}\qquad
b_{ij}=\left\{\begin{array}{ll}
b & \text{if }i=2, j=1;\\
0 & \text{otherwise.}
\end{array}\right.$$
Then the $(1,1)$ entry of $AB$ is equal to
$$\sum_{k=1}^n a_{1k}b_{k1} = a_{12}b_{21} = ab\neq 0.$$
(In fact, all other entries are zero, but that is not relevant to this calculation.)
On the other hand, the $(1,1)$ entry of $BA$ is trivial, since it is equal to
$$\sum_{k=1}^n b_{1k}a_{k1} = 0,$$
because all entries of the form $b_{1k}$ are equal to $0$. (In fact, the only possible nonzero entry of $BA$ is the $(2,2)$ entry, which is equal to $ba$). Thus, $M_n(R)$ is not commutative in this case.
In summary:

If rings must have a $1$, then $M_n(R)$ is commutative if and only if $1=0$ in $R$ (so $R$ is the zero ring), or $n=1$ and $R$ is commutative.
If rings are not required to have a $1$, then $M_n(R)$ is commutative if and only if $n=1$ and $R$ is commutative, or if $R$ is a zero-multiplication ring (including possibly that $R$ is the zero ring).

