Mail app, Flagged count always wrong
Tip: you can go to any folder accessible from your Mac by hitting cmd+shift+G on your keyboard (whilst being in Finder)

According to this answer you can do the following:

• Quit Mail if it’s open.

• In ~/Library/Mail/V7/MailData, delete any file that begins with “Envelope Index,” such as Envelope Index or Envelope Index-shm.

• Your home Library folder is hidden by default. To display it, choose Finder > “Go to Folder” and then enter ~/Library

• Open Mail.

• Mail creates new Envelope Index files. This process may take a few minutes, depending on how many messages Mail is reindexing.