Thank you jtr!
Your links helped me find the solution and fix this problem. Here are the steps I used, in case someone else needs them:
docker stop nextcloud
docker exec -it nextclouddb bash
psql -U nextcloud
ALTER DATABASE nextcloud REFRESH COLLATION VERSION;
REINDEX DATABASE nextcloud;
\q
exit
docker start nextcloud
It’s important to close the nextcloud docker, as the database must not be accessed during the procedure.