You are confusing yourself by not distinguishing between normal program output to stdout and error messages output to stderr.
Executing
str=$(command)
causes command to be executed with its stdout redirected, but without changing stderr. The consequence is that error messages sent to stderr will just appear immediately on stderr, which is presumably still your terminal.
The redirection is to a bash process which captures the output (that is, to stdout) and, when the command is finished, assigns the collected output to the shell variable. If there was an error and nothing was sent to stdout, the shell variable will end up set to an empty string.
So
str=$(command)
printf '\033[31m%s\033[0m\n' "$str"
will directly output error messages, and will capture and later output regular output. (I changed the echo to printf and \e to \033 in order to make the command portable. Also see note 1, below.)
If you just want to colour output, there is no need to capture the output in a variable at all. Just send the appropriate colour sequences before and after executing the command:
printf '\033[31m'
command
printf '\033[0m'
That will colour all output from command. (Of course, the output itself could include colour sequences, but there is no simple way to get around that.)
If you have some other reason to capture the output (which seems unlikely), you could run the command with stderr redirected to stdout. In that case, you will get both stdout and stderr output (intermingled) in the shell variable:
str=$(command 2>&1)
Notes
Although using ANSI colour sequences is probably going to work in any modern platform on which bash is running, some people will recommend the use of the tput command in order to access the terminfo database. For example,
tput setaf 1 # Set terminal to ANSI colour 1 (red)
command
tput sgr0 # Reset all terminal attributes
tput setaf 0 is not the same as the control sequence ESC [ 0 m. setaf 0 sets the foreground colour to black, which will make output invisible if you use a white-on-black console, while ESC [ 0 m resets all character display attributes to their defaults. That's also what tput sgr0 is defined as doing, although it may also reset other terminal attributes. (With my terminfo setting, tput sgr0 outputs ESC ( B followed by ESC [ m; the former resets the terminal font mapping, which I think is redundant in my case. But YMMV.)
It is possible (but unlikely) that there is no setaf entry for your terminal, in which case you are supposed to fall back to setf; however, the colour numbering is different so that setf 1 is blue and setf 4 is red, while setaf 1 is red and setaf 4 is blue. All of these convoluted details are documented in man 5 terminfo. Search for "Color Handling" and enjoy. If you are using Linux, you might also find man 4 console_codes interesting reading.
\ewith\033makes it work.echo "$(tput setaf 1)$str$(tput setaf 0)"should work anywhere (as long as terminal has colour support).