Yum uses an internal database to keep track of the packages that are installed. On rare occasions, this database can get corrupted – usually when a yum update crashes halfway through. There’s a way to rebuild the database, of course.
First, remove the “old” database files. This moves them to /tmp, so you can always recover them again later.
$ mv /var/lib/rpm/__* /tmp/
Then rebuild the database.
$ rpm --rebuilddb
$ rpmdb_verify Packages
That should fix the yum database.
Note: that rpmdb_verify Packages step is specific to the old Berkeley DB backend, where the database lived in a Packages file. RHEL 9, Fedora 33 and newer switched to a sqlite RPM database (rpmdb.sqlite), so rpmdb_verify no longer applies there – on those systems rpm --rebuilddb on its own is enough.