This sounds like it could be "Three Infernal Jokes" by Lord Dunsany, collected in Tales of Wonder (1916), which can be read here at Project Gutenberg.
Devil gives three jokes:
My poor friend duly signed it. "These are the jokes," said the agent. They were boldly written on three slips of paper. "They don't seem very funny," said the other when he had read them. "You are immune," said Mr. Montagu-Montague, "but anyone else who hears them will simply die of laughter: that we guarantee."
Uses the first joke in a club:
The dinner was duly served, the port went round, the twenty men were smoking, two waiters loitered, when he after carefully reading the best of the jokes told it down the table. They laughed. One man accidentally inhaled his cigar smoke and spluttered, the two waiters overheard and tittered behind their hands, one man, a bit of a raconteur himself, quite clearly wished not to laugh, but his veins swelled dangerously in trying to keep it back, and in the end he laughed too. The joke had succeeded; my friend smiled at the thought; he wished to say little deprecating things to the man on his right; but the laughter did not stop and the waiters would not be silent. He waited, and waited wondering; the laughter went roaring on, distinctly louder now, and the waiters as loud as any. It had gone on for three or four minutes when this frightful thought leaped up all at once in his mind: it was forced laughter! However could anything have induced him to tell so foolish a joke? He saw its absurdity as in revelation; and the more he thought of it as these people laughed at him, even the waiters too, the more he felt that he could never lift up his head with his brother touts again. And still the laughter went roaring and choking on. He was very angry. There was not much use in having a friend, he thought, if one silly joke could not be overlooked; he had fed them too. And then he felt that he had no friends at all, and his anger faded away, and a great unhappiness came down on him, and he got quietly up and slunk from the room and slipped away from the club. Poor man, he scarcely had the heart next morning even to glance at the papers, but you did not need to glance at them, big type was bandied about that day as though it were common type, the words of the headlines stared at you; and the headlines said:—Twenty-Two Dead Men at a Club.
Uses the second joke actually in court, while trying to explain what happened with all the dead in the first incident... at first he tries telling the first joke again, but it doesn't work.
No joke sounds quite so good the second time it is told, it seems to lose something of its essence, but Watkyn-Jones was not prepared for the awful stillness with which this one was received; nobody smiled; and it had killed twenty-two men. The joke was bad, devilish bad; counsel for the defence was frowning, and an usher was looking in a little bag for something the judge wanted. And at this moment, as though from far away, without his wishing it, there entered the prisoner's head, and shone there and would not go, this old bad proverb: "As well be hung for a sheep as for a lamb." The jury seemed to be just about to retire. "I have another joke," said Watkyn-Jones, and then and there he read from the second slip of paper. He watched the paper curiously to see if it would go blank, occupying his mind with so slight a thing as men in dire distress very often do, and the words were almost immediately expunged, swept swiftly as if by a hand, and he saw the paper before him as blank as the first. And they were laughing this time, judge, jury, counsel for the prosecution, audience and all, and the grim men that watched him upon either side. There was no mistake about this joke.
He did not stay to see the end, and walked out with his eyes fixed on the ground, unable to bear a glance to the right or left. And since then he has wandered, avoiding ports and roaming lonely places. Two years have known him on the Highland roads, often hungry, always friendless, always changing his district, wandering lonely on with his deadly joke.
As you can see, it ends with him being a wanderer... actually, the story itself starts that way:
This is the story that the desolate man told to me on the lonely Highland road one autumn evening with winter coming on and the stags roaring.
The saddening twilight, the mountain already black, the dreadful melancholy of the stags' voices, his friendless mournful face, all seemed to be of some most sorrowful play staged in that valley by an outcast god, a lonely play of which the hills were part and he the only actor.
For long we watched each other drawing out of the solitudes of those forsaken spaces. Then when we met he spoke.
"I will tell you a thing that will make you die of laughter. I will keep it to myself no longer. But first I must tell you how I came by it."
And ends with the narrator believing he has narrowly escaped hearing it:
He paused, his story told, and then his lip quivered as though he would say more, and I believe he intended then and there to yield up his deadly joke on that Highland road and to go forth then with his three blank slips of paper, perhaps to a felon's cell, with one more murder added to his crimes, but harmless at last to man. I therefore hurried on, and only heard him mumbling sadly behind me, standing bowed and broken, all alone in the twilight, perhaps telling over and over even then the last infernal joke.