You should pass
-t option, so it allocates a tty (terminal) on the remote side for running your script.
Commands that need to prompt for a password (such as
sudo) need a terminal, so they can control terminal I/O, such as preventing output of typed characters, so your password doesn't appear while you're typing it.
When you run
ssh $host (with no command), the SSH client will automatically allocate a terminal (so no
-t is needed), but if you run it with a command, such as
ssh $host /path/to/script then it will not allocate a terminal, since for most commands a terminal is not needed and simply redirecting the standard file descriptors (stdin, stdout, stderr) is enough... The
-t option changes that behavior and allocates a terminal even though you're passing it a command line.
See the documentation of the -t option in the SSH man page. Look for other references to pty or pseudo-terminal on that page (BTW, they call it pty/pseudo-terminal instead of tty since the terminal is not attached to a real device such as a keyboard/monitor or a serial port... for these purposes, it means about the same.)