Following the out-of-storage-space errors while trying to install Visual Studio for Mac the other day, I ended up with 3 emails that I had previously flagged and then unflagged showing up in my flagged items mailbox again (but not showing as flagged).

I tried various combinations of re-flagging, quitting, re-un-flagging, relaunching while holding down various keys, as suggested in various places, but nothing that worked. Finally, I found a suggestion on the Apple forums which did work. This was to move the problematic emails to the Trash mailbox, quit and relaunch Mail (I think), then restore the emails to their previous folders (I had one in the iCloud inbox and two in the Gmail inbox). The three unflagged emails then finally disappeared from the flagged emails mailbox.