The term “flag officer” stems from more primitive years of Earth’s warfighting period, when ships bearing a fleet’s highest ranking officer (ostensibly a commodore or higher) would indicate this fact by flying a certain pennant or ensign. Despite such methods being outdated by 400+ years, the term persists at least into the end of the 24th century, and instead has come to denote someone of great experience and wisdom within the higher echelons of Starfleet.
That said, there’s a common theme running through much of canon Star Trek; despite their lofty positions and sizable achievements, many of the flag officers portrayed aren’t all that great. In some cases, they’re simply breathtakingly incompetent. This is exemplified best by Commodore George Stalker, who decided not only to declare himself in command of the Enterprise, but then proceeded to violate the Romulan Neutral Zone. This is especially egregious, considering he had not one iota of starship command experience under his belt, having served as an administrator all of his career.
In other, more malicious cases, flag officers have chosen to betray Federation principles and the safety of Starfleet personnel in the pursuit of, among other things, the greater good. An example of the above might be found in DS9’s “Homefront”, in which Admiral Leyton recruits the members of Starfleet Academy Red Squad to sabotage the planetary defense network of Earth during the Dominion War. Another is Admiral Mark Jameson, who violated the Prime Directive by providing weapons to a hostage-taker in return for securing their release, an decision that led to forty years of brutal civil war on the planet Mordan IV.