In /etc/shadow, I have a line that begins:
ubuntu:!$6$Pi4BKmX8$........................
Why is there a ! before the $6$ in the hash?
It means that the password is locked. Tools, such as usermod -L add a ! to the password to invalidate it. usermod -U removes the !.
From man 5 shadow
If the password field contains some string that is not a valid result of crypt(3), for instance ! or *, the user will not be able to use a unix password to log in (but the user may log in the system by other means).