The concept was borrowed from Roman religion. When the Roman Republic overthrew the Roman Kingdom in 510 BC, the notion persisted that a king of Rome had to be installed in order to perform certain rituals that the king of Rome traditionally presided over. The Romans therefore appointed a rex sacrorum, literally king of the sacred rites, in order to discharge the religious duties of the king. The rex sacrorum was, of course, a patrician, appointed to the priesthood for life by the pontifex maximus. Another Roman priest given the title of "king" was the rex Nemorensis, an escaped slave who was priest of Diana at Nemi, and who attained his position of uneasy honour by killing the previous incumbent of his priesthood, after showing his worthiness by plucking a golden bough from a sacred tree.
Frazer seized on the notion of this substitute king and made him the keystone of his theory of a universal, pan-European, and indeed worldwide fertility myth. According to Frazer, the sacred king represented the spirit of vegetation, a divine John Barleycorn. He came into being in the spring, reigned during the summer, and ritually died at harvest time, only to be reborn at the winter solstice to wax and rule again. The spirit of vegetation was therefore a "dying and reviving god." Osiris, Dionysus, Heracles, and many other familiar figures from Greek mythology and classical antiquity were re-interpreted in this mold. And the sacred king, the human embodiment of the dying and reviving god, was supposed to have been an individual, made king, chosen to rule for a time, but whose fate was to suffer as a sacrifice, offered back to the earth so that a new king could rule for a time in his stead.
In practice, the hypothesis was vague enough that almost any religious or folklore practice could be reinterpreted to fit its loose requirements, especially if it were annual, or involved fire or vegetation. Osiris and Adonis may fit the mold loosely; it is harder to see how the myth of Persephone and Demeter centers around a dying and reviving god. All manner of traditions were interpreted as representing fragments of the unitary myth of a dying and reviving god, and the human king/victim who was his earthly representative or substitute. Though Frazer's Golden Bough was centered, as a literary device, around the curious institution of the king-priest of Diana at Nemi, it is hard to see how this temporary refuge for a desperate slave represents a fertility deity.
Frazer's hypothesis is no longer accepted by most scholars of anthropology or comparative religion. It is generally seen today as doing too much violence to the explanations the actual preservers of various folk rites have of what they're doing. Especially in British Isles, during Frazer's early twentieth century heyday, it launched a cottage industry of amateurs looking for "pagan survivals" in such things as traditional fairs, maypoles, and folk arts like morris dancing. It was widely influential in literature, being alluded to by D. H. Lawrence, James Joyce, Ezra Pound, and many other writers. Robert Graves used Frazer's work as one of the foundations of his own personal mythology which he expounded in The White Goddess. Most curiously of all, Margaret Murray, the principal theorist of witchcraft as a "pagan survival," used Frazer's work to propose the curious thesis that many Kings of England who died in office, most notably William Rufus, were secret pagans and witches, and whose deaths were the re-enactment of the human sacrifice that stood at the centre of Frazer's myth. This speculation is not widely accepted, even by many neopagans.