I was surprised to see TJ Hooker was an 80s show. I’d always thought it happened before Star Trek, not after.
Anyway, the only thing you can really compare Star Trek (TOS and TNG) to is Star Wars, I think. Both were completely breakaway hits that affected the mainstream public in ways few other TV shows or movies have. So you have these works that are completely unmatched in popularity, then you throw in the fact that they featured relatively unknown actors.
The viewing public didn’t know these people as actors (unlike stars like Cary Grant, Sigourney Weaver, or Brad Pitt); it was their first time seeing those actors and they saw them in these amazing roles. A person’s first association with James Doohan isn’t “Doohan playing Scotty,” it’s “Scotty!” When you get enough people for whom that’s the association, whether or not the people casting for future projects buy into it, they’re still going to shy away from the typecasted actor because they don’t want their project overshadowed by the fact that Scotty is in it.
Even Alec Guiness, an accomplished actor before Star Wars, couldn’t escape the typecasting, because the demographic Star Wars resonated most strongly with had never seen his previous movies. Although with Sir Guinness, his lack of roles post-Star Wars may have been due to other reasons, but it’s safe to say that after Star Wars the movie-going public simply knew him as Obi-Wan.
Guys like Shatner and Harrison Ford can escape typecasting sometimes. My guess is because they’re far more aggressive in seeking out new roles (or their agents are), they have a bit more clout than the other actors, and perhaps they’re just a bit more talented which gives them the edge.
Ford lucked out in having both Star Wars and Indiana Jones play around the same time, so people couldn’t just pigeonhole him; instead of just seeing Han Solo, they had to go, “Wait, so this guy is Solo AND Jones? That won’t do at all, what’s his real name?” And from there Ford earned star power instead of simply being an actor. Even then he got typecasted as being an action hero, but at least that’s a bit broader than Han Solo.
As for Shatner, I don’t know exactly why he escaped typecasting, but I suspect it was due to aggressiveness and an overabundance of personality. He made people see him, not Kirk. The rest of the cast of TOS were not such big prima donnas, I should think, and they lacked the clout he had.
It’d be nice if people were rational enough to understand that the actor and the character are separate entities, but fact is when the majority of people see a face for the first time, the identity attached with that face is what gets remembered, and first impressions are incredibly hard to break.