This is because within quoted strings there is no tilde expansion and tilde expansion comes before parameter substitution in the echo line.
The sequence of expansions is:
- Tilde expansion
- parameter expansion
- command substitution
- arithmetic expansion
- Field splitting
- Pathname expansion
- Quote removal
See the POSIX Shell Specification on Word Expansions for the gory details.