Just to cover my scenario of encountering this error, in case it helps anyone else...
I was renaming my public schema to public_backup then restoring a dump to a recreated public schema.
However on rename, the postgis extensions were staying associated with public_backup.
You should be able to follow the official PostGIS guidance here to re-associate it back to the new public schema.
Note: Unless you are working with an AWS RDS hosted instance like me (where you won't have permission to perform that trick owing to the fact it was installed as the locked down 'rdsadmin' role:
ERROR: permission denied for table pg_extension
In the end, I abandoned the rename strategy and just overwrote the public schema.