\Highlighting \todo-like commands is actually quite a hack due to limitations in the parser. Given the current framework we cannot make it behave correct in all possible cases. See https://sourceforge.net/p/texstudio/feature-requests/739/#dd65 for details.

In your case, you can apply the following alternatives as a workaround:

A) Remove highlighting of \todo-like commands. For this, you have to modify the language definition (see manual). Essentially, copy the original tex.qnfa and delete the context for the \todo commands.

B) Keep the highlighting and just fix the leaking of the math context. If the highlighter got mixed up with a math context, you can add the comment `%$`

to the end of a line to force closing a possibly open math context; i.e.

\todo{$a^{2x}$} leaked math context %$ back to normal here.