We're all sorry for the other guy when he loses his job to a machine. When it comes to your job, that's different. And it always will be different.
The Enterprise is used to test the M5, a computer that could replace the crew and captain of a starship. As can be expected with this sort of test, something goes wrong.
This has to be one of my all time favorites of the show. The interaction of Kirk, Spock and McCoy is just fantastic throughout and the alienation Kirk feels at being replaced with a computer is so well done. I know it's become a cliche for an AI to run amok and start killing people, but this episode illustrates why it's a cliche: it reflects our discomfort and fear of growing useless as technology marches forward.