The entries that I changed were to replace the md5 with scram-sha-256 and remove unnecessary remote IPs.
But it has nothing to do with connecting the server locally with "psql -d postgres -U postgres -h localhost"
But when I try to connect it locally I get this error. So it is related to local connections only and when I pass the hostname or ip of the server it works fine without any issue.
The entry of pg_hba.conf is like below:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only