Problem with aligned environment in latex?

aligned takes an optional argument and so it is mistakening [X] for that option. The way to overcome is to place something innocuous after the {aligned}, but before the [X]. Here I place an empty group {}.

Note that the option, when employed, is a vertical-alignment positioning specification, such as [t] or [b].

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{aligned}{}
 [X] &= 1\\
 [Y] &= 2,
\end{aligned}
\end{equation}
\end{document}

Another solution is to load the mathtools package. The mathtools package is a (very significant!) superset of the amsmath package which also fixes a couple of de facto bugs -- such as mis-interpreting [X] as the optional argument of \begin{aligned} -- of the amsmath package. For more about this bug, see section 2.1 of the user guide of the mathtools package.

To wit,

\documentclass[leqno]{article}
\usepackage{mathtools}
\begin{document}
\begin{equation}
\begin{aligned}
   [X] &= 1\\
   [Y] &= 2,
\end{aligned}
\end{equation}
\end{document}

works exactly as expected:

enter image description here

A nice aspect of this solution is that you needn't remember to insert {} after \begin{aligned} if the next line begins with an object -- such as [X] -- that's encased in square brackets.