Officers found the weapon and more than 800g of the class B drug in the property in Dewsbury after they arrested Umar Shezad.
Leeds Crown Court was told Shezad's house on Ouzelwell Road, Thornhill Lees, was searched after the 27-year-old was arrested on unrelated matters on October 22, 2017.
The cannabis had a street value of £4,470. The weapon was defective due to a loose wire but worked when it was put in place.
Police also recovered a mobile phone which was found to contain text messages offering to supply cannabis.
When interviewed, Shezad said he found the cannabis and the weapon in a flat when he was helping to clear it out after the tenant fell into rent arrears.
He claimed he had taken them home and denied knowing the weapon was a stun gun.
Shezad pleaded guilty to possession of a prohibited weapon and offering to supply cannabis.
He has previous convictions for robbery, burglary and possession of cannabis.
Shezad was also given a community order for possession of a bladed article in a public place in 2017.
The court heard Shezad suffers from schizophrenia but refused to engage with mental health services.
Andrew Dallas, mitigating, said Shezad chose to use cannabis to treat his mental disorder.
He was jailed for 11 months.
Judge Tom Bayliss QC described Shezad's offending as "foolish".