Proof below:  Bash 4Prompt> $(echo hello|sed 's/h/m/'|xargs -I{} ls {} 2>/dev/null|sed 's/ /_/')Prompt> for i in ${PIPESTATUS[@]}; do echo $i;doneOutput> 0Prompt> echo hello|sed 's/h/m/'|xargs -I{} ls {} 2>/dev/null|sed 's/ /_/'Prompt> for i in ${PIPESTATUS[@]}; do echo $i;doneOutput> 0Output> 0Output> 123Output> 0Is command substitution not considered to be run in a foreground shell?  that's my guess.
Why doesn't PIPESTATUS work on pipelines within a command substitution
bash;pipe;command substitution
Because the command substitution is run in subshell, so it made no change to the PIPESTATUS variable of the parent shell. From Command Execution Environment documentation:Command substitution, commands grouped with parentheses, and  asynchronous commands are invoked in a subshell environment that is a  duplicate of the shell environment, except that traps caught by the  shell are reset to the values that the shell inherited from its parent  at invocation. Builtin commands that are invoked as part of a pipeline  are also executed in a subshell environment. Changes made to the  subshell environment cannot affect the shells execution environment.You can get the expected result if you check the PIPESTATUS variable in the subshell:$ printf '%s\n' $(echo hello|sed 's/h/m/'|xargs -I{} ls {} 2>/dev/null|sed 's/ /_/';for i in ${PIPESTATUS[@]}; do echo $i;done)001230