Subtracting matrices of the same dimension, how to make them align?

Macro \vphantom can be used to insert invisible vertical space with the height and depth of the argument:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
  \begin{bmatrix}
    \vphantom{x_1^2}x_1 & 0 \\
    0 & x_2\vphantom{x_2^2}
  \end{bmatrix}
   - \begin{bmatrix} x_1^2 & 0 \\ 0 & x_2^2 \end{bmatrix}
\]
\end{document}

Result


Instead of inserting custom-sized \vphantoms, you could also insert \mathstrut directives -- one each in both rows of the first bmatrix. (Aside: \mathstrut is defined as \vphantom{(}, i.e., a \mathstrut is a vertical phantom with the depth and height of a ( parenthesis.)

\documentclass{article}
\usepackage{amsmath} % for "bmatrix" environment
\begin{document}
\[
  \begin{bmatrix} 
  x_1\mathstrut & 0 \\ 
  0\mathstrut & x_2 
  \end{bmatrix}
  -
  \begin{bmatrix} 
  x_1^2 & 0 \\ 
  0 & x_2^2 
  \end{bmatrix}
\]
\end{document}

The \bracketMatrixstack of the tabstackengine package is automatically \strutted, and so both matrices are of the same height. Note that inter-column gap and inter-row baselineskip can also be set independently, by way of

\setstacktabbedgap{1.5ex}
\setstackgap{L}{1.3\normalbaselineskip}

Here is the MWE.

\documentclass{article}
\usepackage{tabstackengine}
\setstacktabbedgap{1.5ex}
\setstackgap{L}{1.3\normalbaselineskip}
\begin{document}
\[
  \bracketMatrixstack{x_1 & 0 \\ 0 & x_2}
- \bracketMatrixstack{ x_1^2 & 0 \\ 0 & x_2^2 }
\]
\end{document}

enter image description here