The book Martin Luther: A Life by James A. Nestingen describes the indulgences around the time of 1517, and says that they could be bought for oneself or others, typically family members.
An indulgence takes the place of some other form of penance. So, having undertaken a pilgrimage or made some other sacrifice, financial or otherwise, the penitent could obtain indulgences that could be used to satisfy penalties for oneself or for a deceased soul. […]
The slogan [used by John Tetzel to sell indulgences] was, “When a coin in the coffee rings, a soul from purgatory to heaven springs,” and it came complete with lurid portrayals of dead relatives waiting urgently in purgatory for someone to buy their release.
It’s clear that indulgences were sold to individuals for the benefit of their deceased family members. But were they ever sold for the benefit of people who had no family?
For instance, if an orphan or a widow died and there were no family members alive to buy an indulgence, would people in their community be encouraged to buy indulgences on their behalf? Similarly, would indulgences be bought on behalf of nondescript people, like “someone who has been forgotten and has no family members to buy an indulgence”?