Billing is contractual. Contracts determine position in the credits, often right down to the letter size and if other credits may share the same card and if so, how many.
On Bonanza the four co-equal leads had contracts which stipulated the order of the actors would rotate episode by episode, so every 4th segment each would be the in first position, etc.
Because the rest of the Lost In Space cast's credits were negotiated during the making of the pilot, when they added Jonathan Harris the only spot he could have in the titles was the last one, so to make himself stand out he was given a Special Guest Star credit for the entire run of the show.
TNG's opening credits for the main cast gave Stewart the first card, Frakes the second, and the rest were billed in alphabetical order by surname.