Why? Unusefully, because the standard says so:
...replacing the command substitution with the standard output of the command, removing sequences of one or more <newline> characters at the end of the substitution.
Realistically, probably because it always worked like that (considering that POSIX mostly codifies existing behaviour, as far as I understand).
More usefully, it might be so that you can do e.g. this:
echo "$(date +"%F %T") $(hostname): something happened..."
instead of
t=$(date +"%F %T")
t=${t%
}
h=$(hostname)
h=${h%
}
echo "$t $h: something happened..."
That is, most commands that print some single value likely print the newline at the end so that they're more friendly to use on the command line. (Without the shell having to detect the cursor not being at the beginning of line after a command; zsh does that, most others don't.)
But if you're going to use that value in a script for something else, you probably don't want the newline, just the content. This doesn't only go for printing, but also for passing the value as an argument to some command.
The common workaround is to append an extra character and to remove it:
foo=$(printf 'foo\n'; echo .)
foo=${foo%.}
echo "<$foo>"
Or, if you only have a printf
inside the command substitution, use printf -v
where available:
printf -v foo 'foo\n'