You should be using exp_continue to reenter your Expect loop after the password and authenticity checks are done. Try the below:
#!/usr/bin/expect
set prompt "pi@raspberrypi ~ $ "
spawn ssh [lindex $argv 1]@[lindex $argv 0]
set timeout 5
expect {
timeout {
puts "Connection timed out"
exit 1
}
"yes/no" {
send "yes\r"
exp_continue
}
"assword:" {
send -- "[lindex $argv 2]\r"
exp_continue
}
"$prompt" {
send "ls -la\r"
}
}
This is an extract taken from Exploring Expect regarding exp_continue by Don Libes:
When executed as an Expect action, the command exp_continue causes control to be continued inside the current Expect command. Expect continues trying to match the pattern, but from where it left off after the previous match. Expect effectively repeats its search as if it had been invoked again.