color_code=$(…) assigns the output of the … command to the variable color_code, with final newlines stripped off. So you need to produce some output. The code you wrote attempts to execute 1 as a command.
You can use this idiom. Note that color_code will be empty if $COLOR is none of the supported values.
color_code=$(case "$COLOR" in
(red) echo 1;;
(yellow) echo 2;;
(green) echo 3;;
(blue) echo 4;;
esac)
But it isn't very idiomatic. The shell language is geared towards simple combinations of simple commands. This big command substitution is awkward. The command substitution creates a subshell, which is slower than the straightforward method:
case "$COLOR" in
red) color_code=1;;
yellow) color_code=2;;
green) color_code=3;;
blue) color_code=4;;
esac
The main semantic difference between the two approaches is that $(…) creates a subshell, so that any assignment, exit, redirection, etc. that is performed inside has no effect outside.