Your use of optional arguments doesn't match what is expected. Specifically, optional arguments use [..] while mandatory arguments use {..}. Also, \newcommand{<cmd>}[<num>][<opt>]{<stuff>} requires the optional argument to be placed before the mandatory one:
<cmd>[<opt>]{<mandatory>}...
If you wish to have the input you're currently using - specifying the optional argument at the end - you can use the following options:

\documentclass{article}
\makeatletter
\newcommand{\var}[1]{\textsf{#1}}
\newcommand{\LOCa@}[1][\relax]{\ifx#1\relax\else\ensuremath{_{#1}}\fi}
\newcommand{\LOCa}[1]{\var{LOC#1}\LOCa@}
\makeatother
\usepackage{xparse}
\NewDocumentCommand{\LOCb}{m o}{%
\var{LOC#1}%
\IfValueT{#2}{\ensuremath{_{#2}}}%
}
\begin{document}
\LOCa{C}---Without optional argument.
$\var{LOCC}_{1}$---This looks correct.
\LOCa{C}[1]---What happened here?
\LOCb{C}---Without optional argument.
$\var{LOCC}_{1}$---This looks correct.
\LOCb{C}[1]---What happened here?
\end{document}
The xparse interface is easier to understand. Additionally, consider coding your macros without the forced switches (to math mode) in mind. Rather switch to math mode where you use it within your document:
$\LOC{C}[1]$
Reference:
\LOC[1]{C}. – barbara beeton Dec 20 '17 at 22:12