The tilde is expanded in the assignment to
PATH because it is a variable assignment and the tilde comes just after an unquoted colon (in your example).
A "tilde-prefix" consists of an unquoted
<tilde> character at the beginning of a word, followed by all of the characters preceding the first unquoted
<slash> in the word, or all the characters in the word if there is no
<slash>. In an assignment (see XBD Variable Assignment), multiple tilde-prefixes can be used: at the beginning of the word (that is, following the
<equals-sign> of the assignment), following any unquoted
<colon>, or both.
(from the POSIX text on tilde expansion)
bash manual puts it like
Each variable assignment is checked for unquoted tilde-prefixes
immediately following a
: or the first
=. In these cases, tilde
expansion is also performed. Consequently, one may use filenames with
tildes in assignments to
CDPATH, and the shell
assigns the expanded value.
This means that assigning the unquoted string
PATH will expand the tilde within, and that
$PATH will be the string with the tilde expanded.
Placing a literal tilde in
PATH, for example by quoting the string, will cause pathname resolution of commands to fail for that directory (unless there is a directory in the current working directory with that literal name).
bash when not in POSIX mode, will still expand these tildes in
PATH when looking for commands.
When the shell scans the line
it is returned to the parser as a single token. It will be processed as a simple command.
A simple command, when recognised as an assignment, undergoes, among other things, tilde expansion. While doing the tilde expansion on the right hand side of the
=, the shell will expand the tilde in the string to the home directory of the current user, because it occurs just after a colon.
See also the POSIX text on simple commands.