A flag officer was
in command of the vessel in TOS, technically indeed making her a flagship, in both "The Deadly Years" and, arguably, "The Menagerie". We don't know if either officer physically brought his flag aboard (or had one manufactured or brought out of onboard storage), but we're talking about words here anyway, not about physical things.
Ditto for ST2. In the real world, a rusty old training barge can easily be a flagship, as can a humble destroyer if the admiral in question thinks he needs to be in the thick of things and can't afford to stay back on a clumsy battleship.