The situational irony at the heart of “The Cop and the Anthem” is the fact that Soapy is not arrested for any of the blatant crimes he commits in order to be arrested but instead for a “crime” (loitering) he commits after deciding he doesn’t want to be arrested anymore.
The irony comes across in all of the scenes in which Soapy commits a crime and the police look the other way. Take the following interaction, for example, that comes after Soapy throws a rock through a window knowing that a police officer is stationed nearby:
“Where’s the man that done that?” inquired the officer excitedly.
“Don’t you figure out that I might have had something to do with it?” said Soapy, not without sarcasm, but friendly, as one greets good fortune.
The policeman’s mind refused to accept Soapy even as a clue. Men who smash windows do not remain to parley with the law’s minions. They take to their heels.
The situational irony in this scene emerges from the fact that the police officer does not consider Soapy to be a suspect, even though he is the only person who was near the window at the time it was broken. Even when Soapy implies to the police officer that he is the one who smashed it (asking, “Don’t you figure out that I might have had something to do with it?”), the police officer refuses to consider him as a suspect. This moment is also an example of dramatic irony, as readers and Soapy are all aware of his scheme but the police officer is not.
The irony in the story only increases when Soapy is arrested for the least criminal thing he has done so far—resting ("loitering") outside a church. And, further, he is only arrested after being inspired by the church’s anthem and committing to turn his life around. This final layer of irony furthers O. Henry’s point in the story that poverty, houselessness, and crime are all parts of a vicious cycle in which people get stuck—while some may think that all it takes for someone to change their circumstances is the commitment to doing so, in reality, it is not so simple.