In AD&D, the cosmology of D&D which had gradually developed over the course of numerous publications was codified into the Planescape setting, which focused on adventures on the planes besides the Prime Material. The architecture of the cosmology focused on the “Great Wheel,” the sixteen planes surrounding the Outlands. These seventeen planes, collectively known as the Outer Planes, were the provinces of belief: mortal belief became solid matter in the Outer Planes, so that each was made from belief.
Being literally made from belief, the Outer Planes were all about alignment. The Outlands is True Neutral, and then eight of the planes correspond to the various non-neutral alignments. The remaining eight fit in between the others, creating spaces halfway between the various extremes of alignment (so Arcadia lies between LG Celestia and LN Mechanus, and is thus Lawful and Good-ish-but-not-quite-truly-Good).
Each of the planes matching an alignment also spontaneously gave rise to its own “exemplars,” creatures formed of that plane (and sometimes the souls of mortals who ended up there in their afterlives, though the exact process is full of caveats and exceptions and beyond the scope of this answer). The exemplars didn’t merely “believe” in an alignment, they were literally that alignment incarnate.
The nine exemplar races, then, are:
Lawful Good archons from Celestia
Neutral Good guardinals from Elysium
Chaotic Good eladrin from Arborea
Lawful Neutral modrons from Mechanus
- Worth noting: the modrons produce inevitables, constructs of pure law like maruts. Inevitables are not living things and do not form spontaneously and directly from Mechanus itself. Modrons are rather robot-like, but are in fact living outsiders.
True Neutral rilmani from the Outlands
- Extremely obscure and very, very little is known about them. Even in Planescape they were rarely mentioned and extremely rarely had any effect on history.
Chaotic Neutral slaadi from Limbo
Common slaad are all colored frogs, and their color denotes their variety and powers. This consistency is a notably Lawful trait imposed upon them by their sovereigns, who used the Spawning Stone to permanently fix the slaadi in this form to limit them and prevent them from becoming powerful enough to overthrow the Slaad Lords. The Slaad Lords themselves are not frog-like, and indeed can chaotically change themselves significantly. One even did a stint impersonating Primus, the top of the modron heirarchy, in an attempt to spread chaos to lawful Mechanus (or maybe just for a laugh; hard to say with slaadi), though this damaged him significantly.
- It is likely that all of this was made up just to make the Chaotic races reasonably approachable; after all, they had to give stats for these things. Kinda hard to do that if each and everyone is completely random and unique.
Lawful Evil devils from Baator
- While the LE exemplars are generally called “devils,” in particular the ruling class of Baator are the baatezu. Not all devils are baatezu, and in particular, the ancient baatorians, rather than the baatezu, are the original, in some ways rightful exemplars of Baator. The baatezu’s status as usurpers in such a lawful plane causes them many problems (which are, of course, carefully hidden by the most powerful baatezu from everyone else), including the mess with larvae and their constant need to manually purchase mortal souls. But so long as they remain strong enough to overcome these problems and any who would take Baator away from them, Evil recognizes their might makes right and they can bend the plane to their needs and produce more baatezu. The ancient baatorians had largely vanished from the plane before the baatezu even got there; what became of them is one of the greater mysteries of the setting.
Neutral Evil yugoloths, or daemons, of Gehenna and Hades
Gehenna is the plane between LE Baator and NE Hades, and yugoloths were originally from there, rather than Hades. The near-mythical General of Gehenna specifically “purged” the yugoloths of law and chaos with an artifact known as the Heart of Darkness. They now naturally form in both planes, making them the true exemplar of Hades, and they are neutral evil, but some caveats seemed worthwhile. They now mostly operate as notoriously unreliable mercenaries, always open to higher bidding from those they were hired to fight.
Like the baatezu and tanar’ri (below), yugoloths are not the original exemplars of neutral-evilness. The ancient baernoloths, who were the original exemplars, specifically created the yugoloths to replace them, to be the most perfect exemplars of pure evil.
Chaotic Evil demons of the Abyss
- Just as with the other evil exemplars, the current demons, the tanar’ri, are not the original exemplars of chaotic evil; the obyriths were that. The tanar’ri overthrew the obyriths towards the end of the War of Law and Chaos.
And if you’re wondering, yes, there’s a reason the Upper Planes didn’t get any sub-notes: they just never got a lot of attention. They always existed, and had some history and description, traits, stats, and so on, so they aren’t pure mysteries like the rilmani, but they also just don’t have a lot going on. Things are fairly peaceful in the heavens, as it turns out. However, while we’re on the subject, there is one thing about the Upper Planes that does warrant a mention: angels. Angels are not exemplars, and can be any good alignment (barring a fall, of course), but they are in some ways above the good exemplars. They are much, much more powerful, and represent all of Good. They are the direct hands of the good gods. Other alignments lack any similar “arch-exemplar.” So the heavens do have that going for them.
The Great Wheel cosmology was re-used throughout many editions of D&D, though significant changes were made from time to time. Third edition, and the 3.5 revision, largely kept it, except in the new Eberron campaign setting which completely eschewed it. Fourth edition nominally used... something sort of maybe like it, but mucked with most of it. Fifth edition once again is using Planescape as an official published setting.
Best Answer
There's one effect/ability that does this, but you've got to be a sprite... or get one!
(All thanks to @DrunkCynic, who put two and two together.)
In all of the core set and the Encounters supplements I can only find one thing that gets you a sort of divination of alignment: the sprite's Heart Sight ability:
As a third-level Warlock you can gain the Pact of the Chain boon and take a sprite as your familiar: "when you cast [Find Familiar] you can choose... [a] sprite. (PHB p.107)" And now you're just a touch and a telepathic back-and-forth away from knowing one's alignment.
Spells
There's nothing like the old Know Alignment of my youth. But you can Commune and pester your deity for the information.
Alternatively, you've got Glyph of Warding which can trigger on the alignment. (But process of elimination is slow.) Or you might be able to make a case to a GM that Detect Thoughts plus some skill at interpreting those thoughts might get you to alignment, but we're venturing past RAW, here. (Other spells in the ballpark are even more-problematic to try to apply with any surety.)
Magical Items
There are a few magical items that could be used in a process of elimination, as they will harm one of the wrong alignment. These items are: the Talismans of Pure Good/Ultimate Evil and the Books of Exalted Deeds/Vile Darkness. (The Obsidian Steed has a small probability of also achieving this.)
Many items can only be attuned by one of the proper alignment, but I can't think of a way to force another's attempt to attune. If you could, though, we've got a clear winner: the Eye or Hand of Vecna, either of which will change the user's alignment to NE.
[Over]Kill
A coworker reminded me at lunch of the one I'd missed: kill the target, and follow its soul to its eventual destination. Not very practical, but neither are any of the magical items....
For your reference, an Angry GM article on how vestigal alignment has become in 5e. However, he does have some constructive ideas on how to make alignment more relevant, too. (Be warned: Angry GM's materials are liberally... flavored with rude and vulgar language.)