When a command acts strangely, my first question is which one actually runs. which only knows about files. Bash has a fuller answer.
The type builtin with -a prints all the places that contain a command with that name. The bash manual says that includes aliases, reserved words, functions and builtins:
type -a echo
On a Linux machine with bash 5.2 the output is a shell builtin first and then two executables:
echo is a shell builtin
echo is /usr/bin/echo
echo is /bin/echo
The first line is the one bash uses. That is the quick way to see why a command behaves differently from what its man page says: the man page may describe the file, while your shell runs the builtin. Run it on a name like ls and you also find out right away whether an alias has replaced it.
Two related options from the manual:
type -t nameprints one word,alias,keyword,function,builtinorfile, which suits a scripttype -ap namerestricts the output to executable files found by searching$PATH
The caveat is the hash table. The manual says that with -p or -P, a name that is in the table of hashed commands prints the hashed value, which is not necessarily the file that appears first in $PATH. Combining -a with -p avoids that, because type then skips the hash table and does a plain PATH search.
The output wording belongs to bash, so do not parse it in a script. For a script that only needs to know whether a command exists, command -v name is documented in the same manual.
Further reading: bash man page (type builtin)