Answer If A is an m by n matrix, then in order for both AX and XA to make sense, X has to be an n by m matrix. Then AX is an m by m matrix, and XA is an n by n matrix. Now for the two matrix to be equal, we must have m = n. In other words, A has to be a square matrix.
Now assume A is an n by n matrix. Let Eij be the n by n matrix with 1 as the ij-entry and 0 as all the other entries. For example, in case n = 3 we have
|E11 = [||1||0||0||], E23 = [||0||0||0||], E31 = [||0||0||0||]|
Then AEij is obtained by moving the i-th column of A to j-th column, and leaving all the other columns zero. For example,
|AE23 = [||a11||a12||a13||] [||0||0||0||] = [||0||0||a12||]|
And EijA is obtained by moving the j-th row of A to i-th row, and leaving all the other rows zero. For example,
|E23A = [||0||0||0||] [||a11||a12||a13||] = [||0||0||0||]|
Thus from AEij = EijA, we have
Since the above should hold for any i, j, we conclude that aij = 0 for i ≠ j, and aii = ajj for any i, j. This is the same as A = aI, which is a constant multiple of the identity.