I have tried that on an ubuntu:
container and I managed to run that initial command from the shell and reset the password. I also got a warning about an unrelated issue,
$ lxc exec mycontainer -- passwd -d ubuntu
passwd: password expiry information changed.
Have a look at this also, though: Only one lxc exec in a shell while loop