A cannabis user brought a bag of the drug to a Garda station to complain it was "not of good quality".
Arthur Liwembe (34) was immediately arrested when he went to the station of his own accord and presented the cannabis to an officer to say he was not happy with it.
He has been spared six months in jail and instead ordered to carry out 200 hours of community service.
However, Dublin District Court heard he has separately been given a deportation order.
Liwembe, an asylum seeker and former student nurse, pleaded guilty to unlawful possession of cannabis at Kilmainham Garda station on July 10 last year, and other charges.
Defence solicitor Anne Fitzgibbon told Judge John Hughes that since his last court appearance in March, Liwembe had been found suitable for community service. The only problem, she said, was the issuing of an order to leave Ireland by June 22 or present for deportation on June 26.
She accepted this was a separate system and said Liwembe, from Malawi, might appeal as he now wished to stay and work in Ireland.
The accused, who'd had a "very difficult upbringing", was now clean of cannabis.
Judge Hughes said he recalled the case because of "the unusual nature of going to a Garda station" with cannabis. "Looking to be arrested springs to mind," he said.
Ms Fitzgibbon explained Liwembe had been concerned that the cannabis he had bought "could be detrimental to other people's health".
Previously, Garda Ian Foley gave evidence that Liwembe went to the station and produced a bag of cannabis valued at €10 from his pocket.
Judge John Hughes said Liwembe's behaviour was "illogical to say the least" and was indicative of a cannabis-induced "psychosis".
Separately, Liwembe admitted repeatedly trespassing at an address where he used to live and work at Inchicore.
He was under the "misapprehension that he still lived there".