By hanging himself in his prison cell, Aaron Hernandez may have just screwed his murder victim’s family out of recovering any civil damages — all thanks to an obscure, centuries-old snippet of Massachusetts case law.

“Aaron Hernandez will go to his death an innocent man” in the eyes of the law, Martin Healy, chief legal counsel to the Massachusetts Bar Association, told the Boston Globe.

The legal twist results from the fact that when he died Wednesday, Hernandez was still appealing the murder conviction for which he was serving life in prison without parole.

Since his appeal will never be resolved, a doctrine called “abatement ab initio” now gives Hernandez the benefit of the doubt, Healy explained.

The doctrine nullifies Hernandez’s conviction for the 2013 shooting murder of his pal, semi-pro football player Odin Lloyd.

It’s as if the prosecution, trial and guilty verdict never happened.

“Unfortunately, in the Odin Lloyd matter, for the family, there won’t be any real closure,” Healy told the Globe.

Hernandez’s appellate lawyer, John Thompson, told the Globe that the DA could still challenge any motion to vacate the conviction.

But, while rarely used, “abatement ab initio” has successfully wiped clean the records of some convicts, notably in the case of Enron CEO Kenneth Lay.

After Lay died of a heart attack in 2006 — after his conviction but prior to his sentencing for fraud — the doctrine wiped his criminal record clean. The government lost access to $44 million in victim restitution, and his estate went to his family.

So whatever’s left of Hernandez’s NFL millions, including a $1.5 million mansion in a Boston suburb, may now belong to his 4-year-old daughter, Avielle, and her mother, Shayanna Jenkins, to whom Hernandez was engaged at the time of his death.