Let's say I've modded the game to include 20ish possible civilizations and they don't all show up in worldgen. Would it be possible for the races that weren't generated as civilizations to show up as visitors? Also, if a civilization goes extinct during history, can people from it still appear as visitors later?
The first part of that question is no unless you do some weird modding I'll explain in a moment which from what has been said will probably work. The second question would definitely be yes, if the people still exist. Most of the time neither civilizations or the creatures making those civilizations never really go extinct. There's often a king hiding around in a cave somewhere, or maybe a few creatures not from the initial civilization still populating it somehow. Or in the case of the creatures, there'd likely be some outcasts hiding in the wilds, or some that had been abducted by goblins, or just living in another civilization in some form. It will be very unlikely that they'll visit since there'd be very few of them, but maybe if you make a tavern right next to the cave of the old king of the last dwarf civilization, he might come visit.
So while the answer first question in the most basic sense is no, I'm pretty sure you could do some odd things to get it to work. Basically you'd need a way for the creatures from the civilization that never generated to exist without the civilization. In vanilla I think all creatures that have entities only show up from those entities and are never in the wild or something. However, with the next update there'll be creatures like crundles, and aboveground animal people which can join civilizations despite never having had one themselves. So you could add in a [BIOME:SUBTERRANEAN_WATER] [UNDERGROUND_DEPTH:1:2] to dwarves and then if their civilization never showed up a few wild dwarves might still join a civilization and you'd get them as guests potentially. You might need them to be a seperate [CREATURE:WILD_DWARF] though, I don't know if creatures can both be in a civilization and in the wild, it might work, but that could be a backup plan. Of course this would result in the creature being found in the wild and uncivilized, and the visitors you get would only have values and knowledge or whatever from the civilization they joined rather than their own, but it is a way it could probably be done.