Noel Murray at the AV Club has a great guide to the history of the TV detective from the ’50s to the present day (including characters like Perry Mason, Quincy and House who are, essentially, detectives no matter what their official title is).
The eternal appeal of the TV mystery format, I think, is that it takes the biggest weakness of series TV — the incredibly formulaic, repetitive nature of the format — and turns it into a strength. Comedies, dramas, sci-fi shows all struggle to do 22 adventures a year without too obviously repeating themselves, and as I was mentioning the other day, if those shows start out with a formula, the audience and the writers will get restless at all the repetition. But the mystery somehow defies the rule that audiences get tired of repetition; when a show is a mystery, the audience tunes in not only expecting, but wanting certain formula elements like a murder, clues, red herrings, and the unmasking of the killer. Like Little Britain, the detective show somehow makes us want to see the same things over and over.
And if the show is good, it can turn the rigid format into a way to improve characterization and theme; because so many of the plot elements are known in advance, it can focus our attention more on the characters (again, I said if the show is good; a mystery show with formula mysteries and formula chaacters is pretty dire). It’s like a popular song, where many of the structural and harmonic elements are dictated by formula and tradition, and that focuses our attention on the songwriter’s inventiveness within that rigid format.