A cannabis user took a bag of the drug to a garda station to complain that it was "not of good quality".
Arthur Liwembe (33) was immediately arrested after he went to the station of his own accord and presented the cannabis to a garda on duty to say he was not happy with his purchase.
Judge John Hughes said Liwembe's behaviour was "illogical to say the least" and was indicative of a cannabis-induced "psychosis".
He adjourned the case for a probation report.
Liwembe, a former student nurse with an address at an asylum-seekers' reception centre, pleaded guilty to unlawful possession of cannabis and other charges.
Gda Ian Foley told Dublin District Court Liwembe went to Kilmainham Garda Station last July 10 and produced a bag of cannabis valued at €10.
He was searched and a box-cutter knife was found on him. The blade was for use in his work as a handyman, said defence solicitor Anne Fitzgibbon.
Gda Foley told Judge Hughes that he believed Liwembe was suffering from problems at the time.
"He said he had bought the drugs and believed them not to be of good quality and that was why he attended the garda station," Gda Foley said.
He was arrested on a later date when he returned, asked for the confiscated knife to be returned and became aggressive when this was refused.
Separately, Liwembe admitted repeatedly trespassing at an address where he used to live and work at Tyrconnell Road, Inchicore.
The court heard he got in without permission and damaged an internal door on one occasion.
Once, he was discovered in a bedroom and told gardai he was "just trying to sleep" and was under the "misapprehension that he still lived there".
The accused came here from Malawi in 2012 as a student nurse but his visa ran out and he applied for residency on the basis of having an Irish-born child, Ms Fitzgibbon said.
Liwembe had been using cannabis, which could lead to "transient psychotic symptoms", the lawyer added.
He was now off the drug.
Judge Hughes remanded him on continuing bail.