npm run adds node_modules/.bin to PATH while the script runsnpm run adds node_modules/.bin to PATH while the script runs. PATH is the list of folders the shell searches for commands.
When a package has a bin entry, npm puts a link to its command in node_modules/.bin. Then npm run puts that folder at the front of PATH for the script's shell. So the shell finds eslint.
"npm scripts are executed by Node, not by a shell" is wrong. The script still runs in a shell: sh on Unix, and cmd.exe on Windows by default.
Outside npm, npx eslint . runs the local binary in the same way.
Read more