Why `\textcolor` inside math environment unexpectedly changes surrounding text (which is not inside `\textcolor`) to black?

I guess this is basically what David refers to in his latest comment: instead of text=white, use font=\color{white}.

output of code

\documentclass{standalone}
\usepackage[alignedleftspaceno]{amsmath}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}
        \path node[fill=black,font=\color{white}]
            {%
                $%
                    \begin{gathered}
a+b=\textcolor{red}{\text{cvar}}\\
a=\textcolor{red}{\text{cvar}}-b
                    \end{gathered}
                $
            };
    \end{tikzpicture}
\end{document}

You don't really need tikz for this, unless you really need the standalone class: empheq (which loads mathtools) makes it easy to obtain the same result:

\documentclass{article}
\usepackage[alignedleftspaceno]{empheq}%
\usepackage[svgnames]{xcolor}

\newcommand{\myblackbox}[1]{\colorbox{black}{\enspace#1\enspace}}

\newenvironment{myempheq}[2][]{%
\setkeys{EmphEqEnv}{#2}%
\setkeys{EmphEqOpt}{box=\myblackbox,#1}%
\fboxsep=8pt\color{white}\EmphEqMainEnv}%
{\endEmphEqMainEnv}

\begin{document}%

\begin{myempheq}{gather}
  a+b=\text{\color{red}cvar}\\ % THIS LINE WILL BE CHANGED LATER TO INCLUDE \textcolor
  a=\text{\color{red}cvar}-b % THIS LINE WILL BE CHANGED LATER TO INCLUDE \textcolor
\end{myempheq}

\end{document}

enter image description here