The argument of the \ensuremath command is always set in
math mode, regardless of the current mode. Note that math mode
is not specifically invoked in the argument of
the \ensuremath command.
Thus \ensuremath{$\alpha^2+\beta^2$} is not
correct.
The correct form is \ensuremath{\alpha^2+\beta^2}.