Then when $A=\begin{pmatrix}a_1 & 0 \\ a_3 & a_4\end{pmatrix}$ and $B=\begin{pmatrix}b_1 & b_2 \\ 0 & b_4\end{pmatrix}$ I want to show that $$U=\{0\} \iff \{a_1, a_4\}\cap \{b_1, b_4\}=\emptyset$$

We have that $$AX=\begin{pmatrix}a_1 & 0 \\ a_3 & a_4\end{pmatrix}\begin{pmatrix}x_1 & x_2 \\ x_3 & x_4\end{pmatrix}=\begin{pmatrix}a_1x_1 & a_1x_2 \\ a_3x_1+a_4x_3 & a_3x_2+a_4x_4\end{pmatrix}$$

and

$$XB=\begin{pmatrix}x_1 & x_2 \\ x_3 & x_4\end{pmatrix}\begin{pmatrix}b_1 & b_2 \\ 0 & b_4\end{pmatrix}=\begin{pmatrix}x_1b_1 & x_1b_2+x_2b_4 \\ x_3b_1 & x_3b_2+x_4b_4\end{pmatrix}$$

So, $$AX=XB \Rightarrow \begin{pmatrix}a_1x_1 & a_1x_2 \\ a_3x_1+a_4x_3 & a_3x_2+a_4x_4\end{pmatrix}=\begin{pmatrix}x_1b_1 & x_1b_2+x_2b_4 \\ x_3b_1 & x_3b_2+x_4b_4\end{pmatrix} \\ \Rightarrow \left\{\begin{matrix}

a_1x_1=x_1b_1 \\

a_1x_2=x_1b_2+x_2b_4 \\

a_3x_1+a_4x_3=x_3b_1 \\

a_3x_2+a_4x_4=x_3b_2+x_4b_4

\end{matrix}\right.\Rightarrow \left\{\begin{matrix}

(a_1-b_1)x_1=0 \\

(a_1-b_4)x_2=x_1b_2 \\

a_3x_1=x_3(b_1-a_4) \\

a_3x_2=x_3b_2+x_4(b_4-a_4)

\end{matrix}\right.$$

For the direction $\Leftarrow$ we have that $\{a_1, a_4\}\cap \{b_1, b_4\}=\emptyset$, so we have the following:

Since $a_1\neq b_1$ it must be $(a_1-b_1)x_1=0 \Rightarrow x_1=0$.

From the second equation we have $(a_1-b_4)x_2=x_1b_2\Rightarrow (a_1-b_4)x_2=0$, since $a_1\neq b_4$ it follows that $x_2=0$.

From the third equation we have that $a_3x_1=x_3(b_1-a_4)\Rightarrow x_3(b_1-a_4)=0$, since $b_1\neq a_4$ it follows that $x_3=0$.

From the last equation we have $a_3x_2=x_3b_2+x_4(b_4-a_4)\Rightarrow 0=x_4(b_4-a_4)$, since $b_4\neq a_4$ it follows that $x_4=0$.

Therefore, the matrix $X$ is the zero matrix, and so $U=\{0\}$, right?