This relationship is called congruence, and for symmetric (or hermitian) matrices $A, B$ such an $X$ exists if and only if the matrices have the same inertia (the same number of positive, negative, zero eigenvalues). Fro general matrices congruence is much less well known, but it *is* quite well understood, see: https://gauss.uc3m.es/fteran/papers/2010-1.pdf