“The Cop and the Anthem” is set on the streets of New York City at the start of the 20th century. During this time period, the United States was experiencing an industrial boom and, as a result, people from rural areas in the U.S. (and abroad) were flocking to cities like New York for factory jobs. As cities became more populated and the financial divide between the wealthy and the poor grew, more and more people ended up homeless and living on the streets, like Soapy in the story.
It is possible that O. Henry chose not to give Soapy a backstory (or even hint at how he became houseless) so that Soapy could act as a stand-in for houseless New Yorkers generally. That Soapy speaks in an upper-class manner is also likely O. Henry’s way of signaling that falling on hard times can happen to anyone at any time, a subtle message for middle- and upper-class readers who may not have been sympathetic to the unhoused people with whom they shared a city.
Another important element of the setting of the story is Blackwell’s Island (today called Roosevelt Island). The motivation that drives Soapy to commit various crimes is so that he can be arrested and sentenced to spend the winter at “the Island”—shorthand for an actual prison on Blackwell’s Island east of Manhattan that housed inmates for much of the 19th and early 20th centuries.