Function accepts only certain passwords in postgreSQL
That's because you used the wrong format specifier. %I is for identifiers, but the password is a string literal, so you should use %L (and not include the single quotes).
Compare these:
SELECT format('PASSWORD %L', 'gut'), format('PASSWORD ''%I''', 'gut');
     format     |     format     
----------------+----------------
 PASSWORD 'gut' | PASSWORD 'gut'
(1 row)

test=&gt; SELECT format('PASSWORD %L', 'Böse'), format('PASSWORD ''%I''', 'Böse');
     format      |      format       
-----------------+-------------------
 PASSWORD 'Böse' | PASSWORD '&quot;Böse&quot;'
(1 row)

So there were unexpected double quotes included in the password.
But there are bigger problems:
SELECT format('ALTER USER me PASSWORD ''%I''', 'inject'' SUPERUSER --');
                     format                      
-------------------------------------------------
 ALTER USER me PASSWORD '&quot;inject' SUPERUSER --&quot;'
(1 row)

Ha! I can abuse your function to become superuser, because you didn't use proper quoting.