Steps to be executed by ssh that come from the script (rather than from the script's standard input) need to be redirected:
#!/bin/ksh
ssh user1@host1 -P password <<-EOF
sleep 1
ping host3
# other commands to be executed through ssh
EOF
# other commands to be executed after ssh session terminates.
Note that using -P password this way makes user1's password on host1 visible to anyone who runs ps while ssh is running. Consider putting the password in the here-document; then that user's password is only public to anyone with permission to read your script. Depending on your security requirements, you may want to explore other ways to enter the password.