The concept of the Law-Chaos as appearing in fantasy worlds dichotomy originated with Poul Anderson's Three Hearts and Three Lions, although the underpinnings are much older[1]. Law was what humanity and civilization represented - the imposition of an order on savage, unpredictable wilds - while Chaos was what most non-human things thrived upon: the strange, the weird, the random, and above all, the magical.
Michael Moorcock adapted this, although the interpretation of it grew as his universe expanded. In his earlier works Chaos was essentially antagonistic, even to Elric, who drew his power from it; Law were basically the good guys, albeit ambiguously so (imagine living in a village in France in 1944: Nazis are Chaos, definitely bad guys, but the Allies are Law, and your well-being is for them somewhat secondary to fighting their enemies). Over time, the idea of Balance emerged as an alternative to either side, and although in D&D terms it is 'neutral', in Moorcock's writings it basically became the "good" side and emphasis was put on the reflective similarities of Law and Chaos, at which point they're both basically "evil" (at least once Elric fights a demon and is surprised to learn that it is a demon of Law, not Chaos), but this development didn't occur until well after the D&D system was established.
In the first edition of D&D, Andersonian terms used, but were essentially stand-ins for Good and Evil. PCs were supposed to be Lawful, so Chaotic monsters were the ones you were supposed to fight and Lawful monsters the ones to be friendly with. Supplement I: Greyhawk
had an implicit separation of good from evil, presumably to encourage Chaotic PCs in order to make the newly-introduced Paladin class seem to have more restrictions, but this wasn't made explicit until 2nd edition D&D. When AD&D was first released, D&D went back to the simple Lawful-Neutral-Chaos model and, for the first time, good and evil were fully fleshed out as principles and possible player character alignments.
Roger Zelazny's Chronicles of Amber series also makes use of a Law vs Chaos dichotomy, although it is introduced too late to have a defining influence on D&D, it reflects the characteristics of the two as they appear in AD&D: there are numerous good and bad characters on both sides of the Amber/Courts of Chaos conflict.
With each new product or edition the definitions of the alignments evolved slightly, but it always remained complex and confusing or unsuitable for many people, leaving a lot of variant interpretations and house rules (I, for one, am not satisfied with any printed description of Lawful Evil - that should be where a killer with a sense of honor is found, but the rules never support that interpretation). In the end the philosophical differences between law and chaos were discarded, so that Lawful Good meant "exceptionally good" and Chaotic Evil "exceptional evil"; many people already played as if that were the case.
[1] They can be traced to ancient Greek philosophy, with positive concepts like logos and kosmos (order and reason) opposed to negative ones aporia and khaos (confusion and chaos). Nietzsche, with other German scholars of the 19th century, identified these two modes as Apollonian and Dionysian, the idea being that human nature was a merger of civilized Apollonian tendencies with the wild, animalistic Dionysian ones. Some also read similar ideas into the Epic of Gilgamesh.
Interestingly, the Egyptians had a concept of order but two concepts of chaos; one, represented by the god Seth, is the kind of chaos found in markets and nature, that which sometimes causes some destruction but is also the source of creativity and new growth, and the other represented by the serpent Apep, is the violent, primordial chaos that only destroys. What makes this arrangement interesting is that Seth was the protector of order (in the form of Ra) against Apep.
The Rogue, a bowdlerized Thief, was always an Adventurer / Treasure Hunter
For a swords and sorcery genre fictional or legendary root, you could look at the Grey Mouser (from Fritz Lieber's fiction), Cugel the Clever (Jack Vance), the Thief of Baghdad, or Ali Baba. Thieves guilds became a permanent feature of the game once the class was introduced. If Indiana Jones had a D&D class, he'd be rogue or thief. A reasonable argument has been made that the thief (later rogue) was purpose built to be at home in the dungeon.
In a lot of ways, the Thief is the class that treats the dungeon as its home, the one that is uniquely adapted to survive and thrive there. Fighting-Men, Clerics, and Magic-Users are intruders in Gygax’s semi-naturalistic, semi-mythic underworld.
Origins
The original published game had neither Thief nor Rogue. Supplement 1 (Greyhawk, 1975) introduced the Thief. With d4 Hit dice (like a Magic User), a Thief could not go toe-to-toe with anyone (unlike the Fighting Man). The Thief got the +dex benefit for ranged weapons, and had the damage multiples for attacks from behind by surprise (+4 to attack, 2x, 3x, etc damage depending on level).
You had to play a thief cleverly to survive, since your HP were low. The key role, the unique addition to the party that this class introduced was what later became the "skill monkey" due to the climb walls, pick pockets, hide, move silently, hear noises, find traps, read languages, and pick locks skills. Use of magic items and scrolls at later levels were a direct Grey Mouser influence. (This later became Use Magic Device(UMD) and is still part of the 5e Thief Archetype). Another boon was that hobbits (later halflings) and other non-human races were not limited by level in the Thief class. (Greyhawk, p. 4). Hobbits were limited to 4th level Fighting Man otherwise, for example.
Supplement 2(Blackmoor) introduced The Assassin, a sub-class of Thieves whose role was specific: hired killer and spy. This was a step toward that glass cannon(non-spell caster). Interestingly, the Monk (a lawful cleric sub-class) got some of the Thief skills and features. The Assassin took the "back stab" of a thief and went one better: this lethal damage dealer struck from behind, the dark, the flank ... anywhere that you weren't looking.
- About the Assassin: the original and 1e Assassin had d6 hit dice, and a special table where, if the target was surprised, a one roll "success or fail" attempt to assassinate was made. For example, from the table on p. 75 of the 1e DMG, a 5th level assassin has a 55% chance to kill a level 4-5 target with an attempt. That was toned down from the 65% chance a 5th level Assassin had against a 5th level target in OD&D (Blackmoor, p. 5). Success meant a dead target. This was the Thief/Assassin's version of a Magic User's "save or suck" spell, and earned some criticism that it was more appropriate for an NPC. (2e AD&D made the Assassin an NPC or a hireling). Like the nerfing of the disentegrate spell over the editions, the assassination attempt has arrived in its current form as a burst of damage in one strike.
Alignment (which at one time mattered) was restricted: Thieves were chaotic or neutral in the old system, and even in 1e were (by general rule) neither Good nor Lawful (though some DM's relaxed that). Assassins had stricter race and alignment rules in OD&D:
Only humans will become assassins. Assassins are always neutral.(Blackmoor, p. 3).
The Thief allowed non-human PC's a way around the level cap from the original game. That boosted the popularity of the class.
AD&D 1e Thieves were a marked improvement
The Thief rose to 1d6 HD in AD&D 1e and the class came into its own. As with Greyhawk, bypassing the non-human level cap was part of its popularity (Thief was a popular multi-class option for non-humans at the tables where I played, and each non-human class got different thief skill bonuses in the PHB (p. 28)). The Thief was a prerequisite class for the game's first effort at a prestige class: the Bard. You had to gain levels in other classes (Thief and Fighting Man) just to play Bard in that edition, if the DM allowed it. This set up the linkage in the next edition for the Bard as a sub-class of Rogue at character creation.
The Assassin sub-class was reclassified as "evil" (which I believe contributed to its removal in AD&D 2e) and racial restrictions were removed.
Assassins, a sub-class of thief, are quiet killers of evil nature. (AD&D 1e p. 18 PHB){snip} Assassins are evil in alignment (perforce, as the killing of humans and other intelligent life forms for the purpose of profit is basically held to be the antithesis of weal). They can, of course, be neutral as regards lawful and chaotic evil. (AD&D 1e, PHB p. 28).
The final growth spurt came with the Thief Acrobat in the AD&D 1e Unearthed Arcana, which emphasized the 'cat burglar' and acrobatic abilities that later looked like feats.
The primary functions of a thief-acrobat are tightrope walking, pole
vaulting, jumping, and tumbling. (AD&D 1e UA p. 23)
AD&D 2e: Rogues, Warriors, Wizards, no more Demons; D&D Bowdlerized
After a decade of game growth, the social backlash to D&D influenced the scrub and reorganization that the AD&D game got. The Rogue replaced the Thief as the name of the class, with sub-classes of Thief and Bard. The nasty criminal connotation of "Thief" was de-emphasized. The Assassin sub-class was retired as a PC, although it remained as a hireling or NPC. The sales pitch was that adventurers in high fantasy were more like Bilbo, an "honorable" burglar, or Ali Baba, or "The Thief of Baghdad" of the old movie classics.
While many rogues are motivated only by a desire to amass fortune in the easiest way possible, some rogues have noble aims; they use their skills to correct injustice, spread good will, or contribute to the success of an adventuring group. {snip}
Rogues are people who feel that the world (and everyone it) somehow owes them a living. They get by day by day, living in the highest style they can afford and doing as little work as possible. The less they have to toil and struggle like everyone else (while maintaining a comfortable standard of living), the better off they think they are. While this attitude is neither evil nor cruel, it does not foster a good reputation. (AD&D 2e: PHB; class description)
Kits arrived for all of the classes, and customization became a feature to a greater extent than previously. The case was made for this adventurer's alignment to be other than evil / dark / chaotic. This change was consistent with how the company (TSR) was trying to overcome negative publicity from the hysterical '80s. (I won't beat that to death, as we have other answers on that topic, but that's a root of why the class is now called Rogue). The Rogue benefited from Skills, both proficient and non-proficient. The Ninja sub-class showed up as an optional Rogue choice, by way of Oriental Adventures. An Assassin kit was added (rather, restored) in the Complete Thief's Handbook (after some of the anti-D&D hysteria had died down ...).
3.x edition.
The Rogue as you now recognize it arrived, combining the skill monkey feature with the hit-and-run skirmisher / glass cannon melee damage dealer. Find a flank and abuse it; use Uncanny Dodge or Evasion to survive combat. The game became more complex, but there were sufficient choices available to make Rogues interesting. The Assassin returned as a prestige class, the Bard graduated to being its own class. You could emphasize damage dealing, social skills, adventuring skills, and of course multi-classing. Racial class limits were gone, but that had never been a problem for Thieves/Rogues in the first place. Granted, as the Tier framework was recognized and popularized, the Rogue didn't fare well (usually found in Tier 3 or 4) but the class was still playable even if it was hardly a match for a martial class in melee without flankers / flanking.
As far as class perception, you could trip over Chaotic Good rogue / thief characters if you went to a guild meeting. A well known rogue in a popular D&D webcomic is described as CG by her creator.
4e Glass Cannon Strikers
4e's tactical scheme found a good niche for the Rogue: damage dealer / striker who was not that well suited for toe-to-toe fighting. This was consistent with the original scheme in OD&D, but had considerably more depth to it. Skills and non-combat adventuring skills / utility remained, as they had been since the introduction of the thief in OD&D.
5e The Bounded Accuracy Rogue
The Rogue is still the skill monkey, is still able to pursue the "use magic item" path, has amped up the spell casting potential via the Arcane Trickster (thanks to 3.x for that prestige class), and can still go for either skirmisher or "pure" assassin with the Assassin archetype. Like the Pathfinder rogue, the HD are d8, so the option to be something like a Striker or Skirmisher remains. The Rogue Thief archetype retains a lot of the feel of the original Thief, but with less crunch and more HP. With the Mastermind archetype (in both XGtE and SCAG) the Rogue class has finally set up a career path for its Guild Masters, though the similarity to Ivy League MBA's is probably a reach. evil grin
One thing that the current edition has done, though, is to make the surprise attack harder to set up. That said, when the surprise attack can be achieved, the Assassin archetype deals significant burst damage, particularly when attacking with advantage. It comes across as less of a Striker and more a "pure" assassin in the mode of the original Assassin from Blackmoor and AD&D 1e due to how surprise rules in combat are now built.
The Adventurer and Treasure Hunter who uses wit and skill
The Rogue is in a pretty good place, being able to fully enjoy all three pillars of a D&D adventure: Exploration, Social Interaction, and Combat. Even though the details of the game have changed, the Rogue is still the skill monkey who is at home in any adventuring scenario: city (wall climbing, sleight of hand, lock picking), dungeon or wilderness (stealth/hiding, climbing, and exploration), at sea, etc. The Rogue has something to offer any adventuring party. That said, in the CharOp discussions that I've been involved in, the Rogue's cousin class (Bard) is very versatile in 5e, can go nuts with skills, and has a substantial advantage in magic use under the Lore Bard archetype as an Arcane Caster. In some ways, the Bard is a hard rival to the Rogue for "skill monkey" on a small team looking for that role.
Full disclosure: I've played more thief / rogue / bard / assassin than all other classes combined since I started this game in 1975, and as such am biased in favor of this class. I consider the Thief, and now the Rogue, to be the ultimate "pure adventurer and treasure hunter." No, that's not your pouch of coins in my hand, why do you ask?
Best Answer
The origin of spell levels is found in the Chainmail miniatures game, Fantasy Supplement.
There were originally six spell levels in D&D's first version. OD&D as published was related to Chainmail, and the Chainmail fantasy supplement. (See Forward to Men and Magic, E. Gary Gygax, dated 1 November 1973; Chainmail, 3rd Edition, Gygax & Perren, TSR). The spell levels expanded into nine spell levels in the first OD&D supplement, Greyhawk. (TSR, 1975)
Spell Complexity (optional rule) for spell power and difficulty
The origin of what became spell level is found in the Chainmail optional rule for spell complexity1. (p. 33, Chainmail). This was a way to add uncertainty to applying magic to a miniatures table top battle based on the power of the magic user using the spell, and the power of the spell itself.
About spells: there were originally 16 listed. Fireball and lightning bolt in Chainmail were at will missile attacks (p. 31) usable by magic-users. (See Table at the bottom).
The Vancian magic system is explained here. Both the power and complexity of magic are reflected in this original model for how magic works in D&D. The spell complexity rule looks like an early adaptation of the Vancian Magic concept preferred by Gary Gygax: magic is both powerful and risky to use.
(Note that in the quote above, "Wizard", "Sorcerer", and "Warlock" are names for different levels for the same magic-user class, rather than the separate classes we are now familiar with.)
The Spell Complexity table provided a matrix comparing complexity value (1 to 6; later spell level in D&D, see Table at the bottom) matched against the magic-user power rating (later expressed as levels in D&D).
Magic-user power levels go, in ascending order, from Seer to Wizard (Chainmail, p. 32 & 33).
Note: the synonyms for "A magic using person" were not classes (as they'd become in later editions of D&D); they were descriptions of comparative power of the basic class -- magic-user -- that in time carried over into D&D.
How did Complexity(Level) work?
We'll use Cloudkill and Haste (p. 32, Chainmail) to illustrate (inches is used based on the scale for table top battles in this game).
A die roll (2d6) determined whether or not the spell was immediately effective(I), delayed(D), or negated(N). ("Negated" morphed into the saving throw in D&D). These were listed in the matrix as I/D/N.
The matrix showed that for a Warlock casting Cloudkill the I/D/N was 10/9/7 for a complexity 5 spell. A roll of 10 or better provided immediate effect on his target; a 9 or 8 provided a delayed effect (1 turn delay); a roll of 7 or less negated the spell. (Fizzle!) The result for a Sorcerer was 9/8/6: 7 or 8 yielded a delayed effect, a 9 or higher an immediate effect, but a 6 or less was a failure.
The Warlock's result would be 8/7/5, and the Sorcerer's 7/6/4, as above, for I/D/N.
Comment on the number of Spells and point values: the number of spells usable was based on a battle fought out on the table top during the game, not the "game day" (or whatever it took to prepare spells again) that it became in D&D. The power rating of the magic user determined both the number of spells he is able to use and the opportunity cost in choosing a powerful wizard (or a timid Seer) when spending from the point budget for building your whole army for the table top miniatures battle.
From Chainmail into D&D
While many things changed in the transition to the new game style (which included the use of a d20 saving throw versus spells), the level/complexity established a way to use magic while being mindful of the cost versus benefit for using more powerful magic. It also accounts for possible failure in battle based on how good your magic user was. (An early version of 3.x/5e's spell DC?) This choice was analogous to spending points on levies (cheap) versus elite (expensive) troops in that same miniatures battle.
Complexity becomes spell level
Spell complexity became spell level as D&D grew out of the Chainmail Fantasy supplement via play and play testing in the Twin Cities area and Lake Geneva in the early 1970's.
On page 21 of Men and Magic (OD&D, Book I, TSR, 1974) you find Cloudkill as a 5th level spell, and Haste as a 3rd level spell. While not everything ported over one-to-one since D&D was a new form of game, most spells did. (See Table below).
Sixth Level Max in OD&D raised to Ninth Level Max in Greyhawk (Supplement 1)
With that basis established in the original three books, complexity becoming level, the expanded spell list in Greyhawk introduced new and more powerful spells of levels 7 through 9 (many of which had no saving throw). The growth of the game and play experiences by the game's developers informed this additional material, which used and expanded upon the previous convention on how to rate spell power.
Why not spell levels beyond 9?
Based on the editorial comments in both Eldritch Wizardry and Gods, Demigods and Heroes (Supplements 3 and 4 to OD&D) and articles in Strategic Review, it is clear that the game's designers found that they didn't need to make magic more powerful. If you consider how powerful time stop and wish are as 9th level spells, I think you can see their point.
Note: Both fireball and lightning bolt were changed from at-will missile attacks into 3rd level spells in D&D (Men and Magic p.21).
Thanks to @Scott's comment, the following is appended:
When D&D was reissued in the d20 system (D&D 3.0 and later 3.5) a feature that resembles the original Chainmail approach to magic based on complexity was included. Epic spells, like the spells used in Chainmail, had a chance of failure when cast based on complexity of spell and the spellcaster's effectiveness as measured by the games comparative power rating method.
This is similar to the I/D/N die roll based on magic user power level versus spell complexity, although it is far more detailed and designed for role playing adventurers versus table top miniatures battles.
1 There seems to have been some overlap between Chainmail's editions updating, and D&D's development. According to this post at the odd74 boards, Chainmail's 3rd edition was the first to have spell complexity, and it was not in the first two editions of the game. OD&D was published in early 1974, while Chainmail edition 3 was published after that. That temporal relationship renders this answer at least partially incorrect as it is based on the printed edition of Chainmail that I own, which is 3rd edition. It is difficult to tell when the design decision was made for Chainmail, and when it was made for OD&D, and which preceded the other. It may well be that the decision to categorize spells was made for D&D and back filled into Chainmail's 3rd edition.