Solving $X+X^T=tr(X)M$

The remaining case is $M$ symmetric with ${\rm tr}(M)=2$. In this case the set of solutions is $$S=\{\lambda M+A: A=-A^T,\lambda\in\mathbb{R}\}$$ Indeed, If $X=\lambda M+A$ then $$ X+X^T=\lambda(M+M^T)=2\lambda M $$ But this implies also that ${\rm tr}(X)=2\lambda$, So $X$ is a solution.

Conversely, If $X$ satisfies $X+X^T={\rm tr}(X)M$ then, $$ \left(X-\frac{1}{2}{\rm tr}(X)M\right)+\left(X-\frac{1}{2}{\rm tr}(X)M\right)^T=0 $$ So $X=\lambda M+A$ where $\lambda=\frac{1}{2}{\rm tr}(X)$ and $A=X-\frac{1}{2}\lambda M$. That is $X\in S$.


From the equation: $$ \begin{align} X+X^T&=tr(X)M \tag{1}\\ \end{align}$$

it follows that solutions only exist if $M=M^T$, that is $M$ is symmetric, and if $tr(M)=2$.

Define $$X+X^T=2\,S,\quad X-X^T=2\,A\quad \left[S=S^T,\,A=-A^T,\,tr(A)=0\right]$$ then $$X=S+A$$ and it follows that $(1)$ becomes: $$ \begin{align} 2\,S&=tr(S)M \tag{2}\\ \end{align}$$ hence your general solution is of the form: $$X=aM+A \tag{3}$$ where $a$ is some constant and $A$ is any antisymmetric matrix. To test, insert the solution $(3)$ into $(1)$ to get: $$\begin{align} a\left(M+M^T\right)+A+A^T&=a\,tr(M)M \\ a2M&=a2M \end{align}$$