The definition of
Thus we see that it starts with
\noalign. When TeX is doing an alignment (with the primitive
\halign, as is the case with
tabular), when it has scanned a
\cr that ends a row (including the one generated by the table preamble) it expands the next token in order to see if
\noalign comes along. This is how
\hline the optional argument to
\multicolumn work. TeX continues expanding tokens until either it finds
\omit or another unexpandable token.
You have to know that
\NewDocumentCommand uses the e-TeX feature called
\protected; a macro defined with the
\protected prefix will behave as if it were an unexpandable token as far as the scanning mechanism above is concerned: it will be considered equivalent to
\relax for the time being, but it will be expanded normally after this preliminary lookup has ended.
(The same behavior happens for
\protected macros in an
So, never define with
\NewDocumentCommand macros that contain (at the start of their replacement text) things that must be first in an alignment cell, such as
\cline (the same applies for the rule making commands of
The same limitation above applies for commands defined with
\newcommand to have an optional argument, because they are expanded in a delayed fashion that would break the scanning for
\newcommand (without optional arguments) or, if you really need an optional argument,
xparse (but check the documentation for the limitations in this case, for instance you need a mandatory argument after an optional argument).