The message is actually printed by shell, in this case tcsh. You can use
strings /usr/bin/tcsh | grep 'no access to tty'
to ensure that it belongs to tcsh
itself.
It is related to ssh only very loosely, ie ssh
in this case is just the trigger, not the cause.
You should either change your approach and not use HERE DOCUMENT
. Instead place executable custom_script into /path/custom_script
and run it via ssh.
# this will work
ssh user@dest '/path/custom_script'
Or, just run complex command as a oneliner.
# this will work as well
ssh user@dest "cd cs4400/$dest;gcc -o $efile $file;./$efile"