"sudo -u postgres psql postgres" does not ask for password
Postgres has a type of authentication called peer. If you look at pg_hba.conf you may see something like

local   all             postgres                       peer


or like

local   all             all                            peer


The fact you did not get asked for the password has nothing to do with using sudo and everything to do with the fact that you were connecting to a DB that matched the user name and peer authentication was enabled in pg_hba.conf.

If this is a test machine and security is not needed you can use trust instead of peer and then passwords will not be needed. Can not stress enough, trust is only a good option for development and test machines. One should never, ever, use trust on a production  machine.