The opening credits on TV shows(*) work very similarly to those in the movies – it’s just that absolutely no one cares who wrote on directed a TV show, pretty much ever. 😉
With notable exceptions, like all-alphabetical listing, the order the stars appear in is negotiated like everything else as part of their contract. The particular placement the querent refers to, however, is special – it’s the equivalent in TV terms of the “marquee spot” – that spot usually reserved before the movie title to mention a particularly well known star, etc.
Pretty much everything about‘ answer is correct as far as the many many whys of how someone ends up with the spot – for the newcomer who is being pushed as “studio product”, it may be the name recognition angle. For a recurring role played by a big name, it’s the glory of the last spot itself… And many times, it’s just whoever fought for it the hardest.
Ironically, if you read some of the stories about who gets what in both TV and movie credits (dig, dig, dig, they are out there online, but it’s easier to find in actor/show biographies, for sure), you start to dig up some really interesting behind the scenes gossip – many times, taking the “with… as…” spot meant giving up a bit of salary, or some other perk… But oh how glorious it must be, all these years later, to show up like a phantom as the last thing viewers see in the opening sequence… I definitely think whoever gets that spot laughs loudest, longest, and best compared to their on-set nemeses – who may have been better paid, appeared in more episodes, hand more lines, input on stories, etc.
(technically, we’re just talking title sequences, as a lot of modern shows and movies either skip opening credits, or just run text credits in-frame while ACT I “starts cold” (which is, in the end, better for the viewer, it means we get that many more minutes of show back from the bean counters who somehow like to think of an hour as consisting of what’re we down to these days, 42 minutes?!?)