This is due to the fact that when you run a command through ssh (
ssh user@host 'command') it opens a non-login shell. An excellent breakdown of the differences between a login shell and a non-login shell can be found at this question. Essentially, what is causing you issue is that when you run the command through ssh your
~/.bash_profile is not sourced, meaning any modifications to the path it makes will not be available.
The solution is to either move these into your
~/.bashrc, which is sourced on opening a non-login shell, or as you found out, sourcing your
.bash_profile directly in the script.