$
\def\k{\otimes} \def\h{\odot} \def\o{{\tt1}}
\def\LR#1{\left(#1\right)}
\def\op#1{\operatorname{#1}}
\def\vc#1{\op{vec}\LR{#1}}
\def\diag#1{\op{diag}\LR{#1}}
\def\Diag#1{\op{Diag}\LR{#1}}
\def\Unvec#1{\op{vec}^{-1}\LR{#1}}
\def\qif{\quad\iff\quad}
\def\qiq{\quad\implies\quad}
\def\c#1{\color{red}{#1}}
\def\CLR#1{\c{\LR{#1}}}
\def\fracLR#1#2{\LR{\frac{#1}{#2}}}
\def\gradLR#1#2{\LR{\grad{#1}{#2}}}
$Matrix equations can be vectorized
$$\eqalign{
\vc{ABC} = \LR{C^T\k A}\vc C \\
}$$
A Commutation matrix is an orthogonal permutation matrix that transforms between the vectorizations of a matrix and its transpose, i.e.
$$\eqalign{
a = \vc{A} = K^T\vc{A^T} \qif \vc{A^T} = K \vc{A} \\
}$$
Note that if $A=A^T$ then $\,\c{Ka=a}$
Construct the $X$ matrix with the required properties using the all-ones matrix $J$, the identity matrix $I$, the Hadamard product $\h$, and an arbitrary unconstrained matrix $U$
$$\eqalign{
F &= J-I &\qiq &X = \LR{F\h U} - I \\
f &= \vc F &\qiq & \vc{F\h U} = f\h u \\
G &= \Diag f &\qiq & Gu = f\h u \\
}$$
In general, a lowercase letter denotes the vectorization of a matrix with the same (uppercase) name.
Vectorize the linear system and use the pseudoinverse to write
a closed-form solution
$$\eqalign{
&XA = B \\
&\LR{F\h U-I}A = B \\
&\LR{F\h U}A = \LR{B+A} \;\doteq\; C \\
&\LR{A^T\k I}\vc{F\h U} = \vc C \\
&\c{\LR{A^T\k I}G}u = \vc C \\
&\c M u = c
\qquad \{ {\sf implicitly\ define}\;\c{M,c} \}\\
&u = M^+c + \CLR{I-M^+M}w \\
&u = {M^+c + \c Pw}
\qquad \{ {\sf implicitly\ define}\;\c{P} \}\\
}$$
where $w$ is an arbitrary vector and $P$ projects into the nullspace of $M$
Next, enforce the symmetry condition and solve for $w$
$$\eqalign{
&u = Ku \\
&\LR{M^+c + Pw} = K\LR{M^+c + Pw} \\
&\CLR{I-K}Pw = \LR{K-I}M^+c \\
&\c L Pw = -LM^+c
\qquad \{ {\sf implicitly\ define}\;\c L \}\\
&w = -\LR{LP}^+ LM^+c \\
}$$
Substitute this back into the $u$ equation
$$\eqalign{
\def\BR#1{\Big(#1\Big)}
u
&= M^+c - P\LR{LP}^+ LM^+c \\
&= \BR{\,I - P\LR{LP}^+ L\,}\,M^+c \\
}$$
Finally, undo the vec operation and construct $X$
$$\eqalign{
U &= \Unvec u \\
X &= \LR{F\h U} - I \\
}$$
For the final question, setting $B=0$ simply makes $C=A$