To remove the need to enter user1's password, you can mess with the sudo
-A
or -a
options on $node_name to get authentication to happen automatically in some other way.
To remove the need to type user2's password, you can try something like this:
ssh -t user1@$node_name "sudo echo $newpass | useradd user2 --stdin"