As we all know Kirk never liked being an admiral because his heart always was in the stars......not at a desk. For him, getting demoted to Captain and getting to be the captain of another Enterprise was heaven.
But why is it there are times when admirals get to actually captain their own ship? In the series finale of TNG Admiral Riker was the "captain" of the Enterprise 1701-D which was still in service after all of those years in that alternate future.
Was it ever explained in any of ST lore how Admiral Riker was able to do this and not be stuck behind a desk for the rest of his Starfleet career?
Admirals don't seem to be constrained to desks per say.
Some opt to do so if they don't feel like going out into sp.ace... so they devote themselves to stationary positions such as planets, outposts and starbases probably (reading up on intelligence reports, giving out assignments, and whatever else admirals are privy to).
Other admirals apparently have the ability to chose their own command and pretty much do the same as stationary admirals, just in the field.
Riker wasn't the first one. During the Borg invasion of Wolf 359, one of the admirals (an old timer) was stationed on one of the ships.
Also, in the First Contact movie, there was an 'admiral's ship' which was destroyed by the time the ENT-E showed up.
Granted, those were battle situations, so its not exactly unreasonable to think an admiral would be deployed into space for the purpose of coordinating the fleet (but strictly speaking, an Admiral is not needed for that purpose... because any seasoned officer could take over command of the fleet - like Picard did - one wonders why no other SF captian in that battle did the same).
But, its not that uncommon.
Also, as we saw in ST: Prodigy that vice admiral Janeway was in command of the Starfleet built USS Dauntless because she set out to search for Chakotay and the Protostar.
Its also possible that admirals having their own commands wasn't common until the 24th century.
As for the Ent-D being still in service in 'All good things' (alternate future)... again, not something that would be uncommon.
Excelsior class ships have been in service for over 80 years... some (like the USS Lakota) were upgraded before the Dominion war, and their tactical abilities rivaled some of the most powerful ships of the late 24th century (such as the Defiant).
So, Ent-D being in service for several decades is nothing really. The original Enterprise (the one from TOS) was in service for what... 50 odd years?
If the Ent-D wasn't destroyed in 'Generations', that ship could easily be in service for at least 200 years or more.
In fact, SF could easily just take an existing Galaxy class ship built in say 2363, and do a major refit twice a century (repeating this cycle endlessly).
I'd also expect that like Discovery, that a major upgrade which results in reshaping of its hull could also come with a letter change (again, once every century or so).
Its overall shape would probably change over time... and because of replicators, transporters and tractor beams, the entire superstructure could be exchanged in a single trasnport cycle for modern one (same shape for example but contemporary materials - and even change the shape itself if SF came up with a better one).
Same with the interior and exterior.
It wouldn't be much of an issue for SF to keep upgrading ships (and changing them) in active service and never retire them (unless they become famous enough or end up destroyed).
Upgrades and 'refreshes' would keep the ships on par technologically with modern ones and just as good as brand new ones.