For the same reason you need \xdef
, you need \xglobal\definecolor
(section 2.5.5 in the manual of xcolor
).
\documentclass{article}
\usepackage{xcolor,pgffor}
\foreach \name/\col in {%
first/{204, 0, 0},%
second/{0, 102, 0},%
third/{0, 0, 153}%
}{%
\xglobal\definecolor{\name}{RGB}{\col} % buggish line
\expandafter\xdef\csname\name\endcsname##1{\noexpand\textcolor{\name}{##1}}
% + more convenience utilities..
}
\begin{document}
here is a \first{custom}-\second{colored} \third{text}
\end{document}

I'd be wary about using such an approach, because you risk to overwrite commands, with possibly disastrous effects.
Here's code that's free of that problem (colors are silently overridden, though):
\documentclass{article}
\usepackage{xcolor,xparse}
\ExplSyntaxOn
\NewDocumentCommand{\definebunchofcolors}{m}
{
\clist_map_inline:nn { #1 }
{
\iagolito_define_color:n { ##1 }
}
}
\cs_new_protected:Nn \iagolito_define_color:n
{
\__iagolito_define_color_aux:nn #1
}
\cs_new_protected:Nn \__iagolito_define_color_aux:nn
{
\definecolor{#1}{RGB}{#2}
\cs_new:cpn { #1 } ##1 { \textcolor{#1}{##1} }
}
\ExplSyntaxOff
\definebunchofcolors{
{first}{204, 0, 0},
{second}{0, 102, 0},
{third}{0, 0, 153}
}
\begin{document}
here is a \first{custom}-\second{colored} \third{text}
\end{document}
However, you don't gain much with this approach: it's simpler to do one declaration at a time.
\documentclass{article}
\usepackage{xcolor,xparse}
\ExplSyntaxOn
\NewDocumentCommand{\setupcolor}{mO{RGB}m}
{
\definecolor{#1}{#2}{#3}
\cs_new:cpn { #1 } ##1 { \textcolor{#1}{##1} }
}
\ExplSyntaxOff
\setupcolor{first}{204, 0, 0}
\setupcolor{second}{0, 102, 0}
\setupcolor{third}[rgb]{0, 0, 0.6}
\begin{document}
here is a \first{custom}-\second{colored} \third{text}
\end{document}