Warning: This post discusses major plot points of Deadwood's three seasons. If you haven't watched the show and intend to, consider this a categorical spoiler alert.
In law school, my professor for Property was an interesting fellow named Robert Ellickson. Unlike most legal academics, who tend to specialize in parsing abstruse constitutional nuance, Ellickson's scholarship had an empirical bent. His best known work is a book called Order Without Law. In that book, Ellickson studied how Western cattle ranchers resolved disputes arising out of damage caused by escaped cattle. Contrary to the assumptions of legal academia, which, unsurprisingly, focus on the law's centrality in human interactions, Ellickson found that dispute resolution among the ranchers was actually conducted via social norms that did not necessarily follow the actual law. It wasn't just that the ranchers didn't utilize the law in the sense of hiring lawyers and filing lawsuits; they also didn't resolve the dispute in the same way as the law would have. Ellickson's main point is that, in the vast majority of day-to-day social interactions, even those involving disputes, the law isn't especially relevant. Instead people are governed by their surrounding social norms. (This may strike some as merely common sense, but at a law school it is practically apostasy.)
I have no idea whether David Milch is familiar with Professor Ellickson's work (or, for that matter, whether Ellickson is familiar with Milch's). But thematically, Deadwood is about precisely this question: how human beings form a society in the absence of law. Indeed, this theme was the genesis of the show; it actually pre-dated the show even being a Western. In an interview with Salon, Milch gave the following answer to the question of how he first became interested in writing Deadwood:
"I had proposed to HBO a series about the city cops in Rome at the time of Nero. What had interested me was the idea of order without law. [emphasis added] The Praetorian Guard, who were the emperor's guards, understood how they were to proceed. But for the city cops, who were called the Urban Cohorts, there was no law at all. So they were sort of making themselves up as they went along. I wanted to focus on that idea of how order is generated in the absence of law. They [HBO] were already doing a show about Rome in the time of Caesar, so they asked if I could engage the same themes in a different setting, and that was how I decided to do the western."
The reason the show is about Deadwood is because of the camp's unusual history: it was not initially recognized as part of the United States. One of the guiding concerns of the characters, particularly in the first season, was whether any agreements they had governing property, the basic societal building block of who owns what, would maintain their validity when and if the camp was brought into the United States.
The changes in the town's organizational structure are perhaps best reflected by the show's most memorable character, Al Swearengen. At the start of the show, Swearengen is the most powerful man in Deadwood, and also a full-fledged villain, albeit a compelling one. By the show's end, Swearengen has become something close to a conventional protagonist, and he has also seen his power (and his body) severely diminished.
The arrivals of Seth Bullock and Cy Tolliver combine to eventually break Swearengen's hold on power in Deadwood over the course of the first season. Tolliver is essentially a peer of Swearengen as he sets up a rival saloon, gambling establishment, and whorehouse, ending Swearengen's near-monopoly on vice in the camp. (The No. 10 Saloon, where Wild Bill Hickok meets his end, is clearly small-time compared to Swearengen's Gem.) Over the course of the first season, the rudiments of government begin to appear in the camp, such as the meetings of the town's unofficial power brokers, at which Swearengen religiously serves canned peaches (despite the fact that eating them often seems to lead to illness). E.B. Farnum is appointed mayor, although clearly this is a token with no weight. Seth Bullock's becoming sheriff, on the other hand, is essentially the first season's climax.
Bullock continues as the town's unquestioned sheriff for the rest of the show, despite the facts that 1) he is self-appointed, and 2) there are no actual laws to enforce. His authority is accepted by the camp, and he often acts more as a mediator than as a conventional law enforcement officer. He also doesn't hesitate to use violence in his role as sheriff.
The early lawless order that is established over the first season and which holds, tenuously, over the second, is increasingly disrupted and finally overthrown by the arrival of George Hearst. Hearst represents the arrival of a different sort of capitalism to Deadwood, the moment when the individual prospectors and the small businessmen of the camp are largely muscled out by a wealthy man who has a seemingly endless array of minions at his disposal. Once Hearst arrives on the scene, the alliance between Bullock and Swearengen is solidly established, and Swearengen's transformation from captivating villain to flawed hero is complete.
The climax of the third season -- or one of them, anyway -- are that elections are held. These elections cover not only Deadwood, but "the county." The county! Yes, Deadwood has been integrated, and takes its final step towards more conventional law and order. Of course, Deadwood's first elections are the precise opposite of a moment of triumph. The fix is in: George Hearst has seen to it who will win, which means the end of Seth Bullock's law enforcement career. Indeed, the first formal step towards Deadwood becoming "civilized" is actually nothing more than Hearst consolidating his power and displacing those who laid the groundwork for Deadwood becoming a civil society.
The third season of Deadwood, in particular, invokes Robert Altman's classic McCabe and Mrs. Miller. One of a series of brilliant films Altman made that deconstructed the genre they nominally occupied -- MASH, The Long Goodbye -- McCabeis an anti-Western. As with the third season in Deadwood, the story revolved around small-time individuals in an isolated and primitive western community who find themselves on the wrong side of powerful and amoral mining interests. If you like Deadwood and haven't seen McCabe, you owe it to yourself to take a look.