The medieval era actually had a pretty decent number of wandering mercenaries and adventurers, many of whom were displaced people from the neverending ongoing local wars across the centuries. (Of course, these groups were also basically interchangeable with bandits if they were broke.) Just look at the Varangian Guard, which recruited itinerant soldiers from all over Northern Europe from the 900s pretty much right up until Constantinople fell to the Ottomans.
This all kicked into even higher gear in the Renaissance and later. As central monarchical control grew, so did army sizes and the impacts of those armies, leading to entire villages being wiped out or displaced entirely as a side effect of being in the way of an army passing through. Conflicts like the Thirty Years' War led to immense numbers of deaths and famine (current estimates say 4-8 million deaths just from the Thirty Years' War, for example), and consequently to immense numbers of migrants looking for work anywhere they could.
The part that didn't exist was, of course, the dungeons. There was no nominally ethical-concern-free money sitting around underground; the source was other people, willing or not. But the whole point of D&D was to have a small-scale alternative to the "armies or mercenary companies fighting each other" gameplay that it originally sprang from, so I can give a pass on that, even if the writers never actually figured out any coherent setting explanations for it.