EDIT: Jeff Rients already did pretty much this exact post.
One of the more charming sections of The Underworld & Wilderness Adventure deals with procedural determination of castle inhabitants and their reaction to the party. My favorite part is "Types of Guards/Retainers":
d6 - Occupant & Types of Guards/Retainers in Castle
1. Lord (9+ level fighter) with (d4): 1. 1-8 Champions (7th level fighters), 2. 1-6 Griffons (with 4th-level fighter riders), 3. 1-10 Myrmidons (6th level fighters), 4. 1-4 Giants (any variety can be neutral or chaotic)
2. Superhero (8th level fighter) with (d4): 1. 1-8 Myrmidons (6th level fighters), 2. 1-4 Rocs (6 HD lawful giant eagles, with 4th level fighter riders), 3. 1-4 Ogres (may be neutral or chaotic), 4. 1-10 Swashbucklers (5th level fighters)
3. Wizard (11+ level magic-user) with (d4): 1. 1-4 Dragons (any alignment), 2. 1-4 Balrogs (chaotic), 3. 1-4 Wyverns (neutral), 4. 1-4 Basilisks (chaotic)
4. Necromancer (10th level magic-user) with (d4): 1. 1-4 Chimeras (neutral or chaotic), 2. 1-6 Manticores (chaotic), 3. 1-12 Lycanthropes (any alignment), 4. 1-12 Gargoyles (chaotic)
5. Patriarch (lawful 8+ level cleric) with (d4): 1. 1-20 Heroes (4th level fighters), 2. 1-6 Superheroes (8th level fighters), 3. 1-10 Ents, 4. 1-8 Hippogriffs (with 4th level fighter riders)
6. Evil High Priest (chaotic 8+ level cleric) with (d4): 1. 1-10 Trolls, 2. 1-6 Vampires, 3. 1-20 White Apes, 4. 1-10 Spectres
Also every castle has 30-180 men-at-arms and possibly some flunkies of 3rd-8th level depending on the character class of the castle master.
Although AD&D and B/X D&D contain similar rules, they don't have the awesome table for determining what monsters serve the castle master, obviously a grave omission on the part of later editions...
A DM can use the alignment of the generated monsters to determine the alignment of the castle inhabitant (unsurprisingly magic-users seem to exhibit a tendency towards chaos...).
An enterprising DM could easily expand the above tables or substitute entries with other creatures of similar power and "theme."
The AD&D Dungeon Master's Guide has a similar, yet more complicated table, that determines castle type & size, and includes the possibilities of the castle being deserted; deserted with monsters; inhabited by a band of bandits, brigands, berserkers, or dervishes; as well as druids, paladins, rangers, illusionists, monks, thieves and assassins.
But it sadly does not include a table to determine what monsters serve as the special guards. What kinds of monsters would serve as guards for illusionists, monks, assassins (giant snakes?), etc.?