Thirteen years ago, William Stewart Boyd, a Cook County judge, drove to a South Side church to turn in a handgun his late father had owned.

The Chicago Police Department was accepting guns as part of a buyback program meant to take weapons off the streets and help make the city safer.

Boyd, who hears domestic relations cases, brought them his father’s .38-caliber Smith & Wesson revolver, serial number J515268. He remembers handing it to plainclothes officers who wore their badges and service weapons on their belts. Under the buyback program, they, in turn, gave him a prepaid Visa card. It was for less than $100.

The police recover thousands of guns every year, many of them through buyback programs like this, as well as by confiscating weapons seized during arrests — more than 5,000 guns so far this year alone.

The guns are supposed to be destroyed. But the gun Judge Boyd took in somehow wasn’t. Instead, it turned up eight years later next to the body of a young man who was shot to death by a Cicero police officer.

The cop — Officer Donald Garrity, who, records show, had a history of discipline problems — is now out of the suburban department and collecting a disability pension as a result of post-traumatic stress he blames on the shooting.

How did a gun Chicago cops were supposed to have kept in a locked custody room and then destroyed end up all of those years later at the scene of a police shooting in Cicero, on a patch of pavement next to the body of a 22-year-old Latin Counts gang member named Cesar A. Munive?

That’s something that Boyd, a judge for nearly 20 years, would like to know.

“I’m doing the right thing,” he says, “and, in the process, someone didn’t do what they were supposed to do. That calls into question the process. What’s happening after you turn these weapons in?”

Police departments in Harvey, Elmwood Park and Dolton all have had guns vanish in recent years. And long before Boyd’s gun disappeared, a city audit found that the Chicago Police Department lost track of more than 130 guns that were stored at an evidence warehouse in the 1990s. Four of those later were seized during arrests.

Now, the Chicago department has opened an internal affairs investigation into how the judge’s revolver ended up in Cicero — something police spokesman Anthony Guglielmi calls “extremely abnormal and troublesome.”

After being informed by a reporter where the gun ended up, Guglielmi says: “We are opening an internal affairs investigation today to trace this gun, verify that it was taken into police custody during a turn-in and investigate how it possibly ended up back on the street.”

Whatever happened to keep the gun from being destroyed, Munive’s family members believe they know how it ended up next to his body. It was planted there by Cicero police to cover up an unjustified shooting by a cop of an unarmed man, according to a civil rights lawsuit the family filed in federal court.

Now, after five years of litigation, Cicero officials are poised to pay the family $3.5 million to settle their case. The Cicero Town Council agreed earlier this month to approve the settlement and is expected to take a final vote soon.

Jon Loevy, the Munive family’s attorney, questions how the Chicago police could have allowed the gun Boyd turned in to have escaped destruction.

“Our guy is dead, we can’t ask him,” Loevy says of the gun. “But we do know it was last seen in the possession of law enforcement.”

Though the town of Cicero is settling the case, officials have denied in court filings that the police used the gun as a “throwdown” to justify shooting Munive.

Garrity, the now-former Cicero cop who shot him, didn’t respond to interview requests. Nor did an officer who was there with Garrity that day in July 2012.

Garrity’s lawyer, Craig Tobin, says Munive got the gun from another member of the Latin Counts gang and that his client didn’t plant it.

The revolver’s long journey began 40 years ago. That’s when Boyd bought it for his father. He wanted him to feel safer, the judge said in a June 29 affidavit in the federal case.

Many years later, after his father had died, Boyd turned in the gun.

It took quite some time before the judge found out it wasn’t destroyed.

Munive — who had a rap sheet that included convictions for battery, sexual abuse of a minor and unlawful use of a weapon — was shot dead by Garrity in a residential neighborhood on July 5, 2012, records show.

Garrity and another Cicero cop told investigators later that they had responded in separate patrol cars to reports of a gang fight and saw Munive riding away on a bicycle. Garrity said he got out of his squad car and ran after Munive, catching up with him at the northeast corner of 13th Street and South 57th Avenue, according to police reports.

Garrity told investigators he saw Munive aim the gun at the windshield of a white, unmarked police car being driven by the other officer, Dominic Schullo. Garrity said he ordered the young man to drop the gun, and Munive didn’t, so he shot him.

Days after the shooting, Schullo told the Illinois State Police — which routinely investigates police-involved shootings in suburban Cook County — he was “staring straight down the barrel of the handgun” he said Munive was holding in his left hand.

Separately, Schullo told his own department: “He was gonna shoot me through the window. If it wasn’t for Garrity, he would have shot me right through the glass.”

The Cook County medical examiner’s office found that Munive was killed by a gunshot wound to the back. The bullet Garrity fired pierced Munive’s right lung, his autopsy found. He struggled to breathe and complained to police that “it burns,” records show.

It was nearly two years after Munive’s death that the Illinois State Police asked the federal Bureau of Alcohol, Tobacco, Firearms and Explosives to trace the gun. The trace identified the judge as having bought it from an Oak Lawn gun dealer in 1977.

Boyd says no one from the police contacted him about the gun, though. He says he learned what happened when he was contacted by private investigators and attorneys on both sides of the lawsuit.

The Illinois State Police and Cicero each says it was the other’s responsibility to get the gun traced. But that didn’t matter anyway because Munive had it, according to Matt Boerwinkle, a state police spokesman, who says his agency stands by its findings that Munive pointed the gun at Garrity before being shot.

“Anybody could allege anything after the fact and file a lawsuit,” Boerwinkle says of the allegations the gun was planted near Munive’s body by police.

Based on the state police findings, the Cook County state’s attorney’s office closed its review of the shooting with a letter that read in part: “We have completed our review of the matter and found no conduct by the officer which would give rise to criminal charges.”

After the shooting, Garrity was promoted from patrol officer to detective.

He left the police department a little over two years ago after developing PTSD, according to Jerry Marzullo, the attorney for Cicero’s Police Pension Board.

Garrity was making $84,707 a year when he left the department — nearly $27,000 more than he made as a patrol officer. That higher pay boosted his yearly disability payments to $55,000.

Cicero Town Attorney Mike Del Galdo says Garrity went on disability after sworn, pretrial depositions in the lawsuit revealed he had omitted key facts about his work history when he first applied for a job with the Cicero police. Garrity had resigned as a Berwyn cop in May 2008 after being arrested by North Riverside officers who pursued him as he sped down Cermak Road in his personal car, records show.

Records also show that, while still with the Berwyn police, Garrity was once investigated for violating orders by wielding a high-powered rifle during a felony traffic stop.

“This police officer should not have been a police officer,” says Loevy, the Munive family attorney. “They are going to pay a substantial settlement as a result of this . . . shooting.”

READ MORE: Cop’s wild ride — caught on dash-cam video — not too wild for Cicero, Feb. 12, 2015

Casey Toner is an investigator for the Better Government Association.

MORE FROM THE WATCHDOGS: Crime on the L, CTA buses is up; 90% of serious incidents go unsolved