Here, it's easy because the file you've messed up is only used by interactive logins. If you'd messed up
~/.zshenv, or if your login shell was bash and you'd messed up
~/.bashrc (weirdly, bash reads
~/.bashrc if it's a non-interactive login shell and its parent is
sshd), none of the methods that rely on executing a command non-interactively would work.
SSH insists on running a shell. If you have no other way to log in (via another account or via a method other than ssh), then your only recourse is to press Ctrl+C really fast after you're authenticated and before the shell reaches the problematic line. In practice, this can often be done manually; it may help to arrange for the machine to be heavily loaded (CPU or disk). If you have trouble pressing the keys at the right time, try using