BOSTON — The Supreme Judicial Court on Friday overturned the larceny conviction of a former Lowell building inspector, determining the judge erred by not requiring proof that the man knew the victim was mentally incapacitated.

The SJC vacated the verdict against David St. Hilaire, who was found guilty by Judge Mitchell Kaplan on charges that he had stolen the home of his elderly neighbor.

Erika Magill, then 86, lived next door and had said she was adamantly opposed to selling her home to St. Hilaire, according to the SJC. But when she was in bed at a nursing home about two weeks before her August 2010 death, she signed the deed over to St. Hilaire and later told her health care proxy she didn’t know what she had signed.

The SJC affirmed mental incapacity can be used as an element of a larceny conviction, but said Kaplan erred in not instructing himself to consider whether the prosecution proved St. Hilaire knew of the victim’s mental incapacity.

“The defendant’s claim at trial that he honestly believed the victim voluntarily and intelligently executed the quitclaim deed transferring her property to him implicates this principle,” read the opinion by Justice Geraldine Hines.

She wrote the prosecution “must prove beyond a reasonable doubt that the defendant knew that the victim lacked the mental capacity to consent to the transaction.”

St. Hilaire collapsed when Kaplan issued his verdict in May 2012. St. Hilaire retired in February 2011, according to the city’s Retirement Board.