West Yorkshire Police officers made the discovery after being given a tip-off about the weapon being at Stephen Teale's flat in Morley.
Leeds Crown Court heard the rifle had been stolen from a gunsmith in Sheffield in April last year.
On August 8, police received an anonymous tip-off that the weapon could be found at the 65-year-old's home on Horsfall Street.
Officers found the weapon in a bin liner inside a communal bin outside his flat.
Jessica Randall, prosecuting, said the rifle had been dismantled into its component parts.
Two bullets were found lodged in the barrel. A metal burr was in the chamber preventing it from being fired but it was capable of being removed to discharge ammunition.
Teale was arrested and his DNA and fingerprints were found on the weapon.
Teale said he had knowledge of firearms from his military service and he had dismantled it.
The defendant said he believed the other man had then tipped the police off because he was angry that the weapon had been taken apart.
Teale pleaded guilty to possessing a firearm without a certificate.
He has previous convictions for producing cannabis and possessing crack cocaine.
The prosecutor said the incident caused alarm for Teale's neighbours.
Mr Khokhar said Teale had been in custody since October last year.
A probation officer told the court that Teale had stated in interview that he had not made police aware of the weapon because he "feared for his safety as he would appear a grass."
The court heard Teale had been a drug user for 20 years and the man who brought the gun to his home also supplied him with drugs.
The officer said: "Whatever has gone on here suggests that he has links with organised criminals."
Teale was given a four-month prison sentence.
He was told he would not be returned to jail due to the amount of time he has already spent in custody.
Judge Neil Clark said: "You should have contacted the police because these things are lethal and the matter is serious."