BELFAST — A judge who sentenced Todd Gilday to serve 50 years in prison on Wednesday called his shotgun rampage last summer an “utterly senseless” act that led to the death of a woman in her own home and seriously injured her son.

Todd Gilday, 44, was sentenced in Waldo County Superior Court under the terms of an agreement reached on July 21 when he pleaded guilty to a charge of murder for the death of Lynn Arsenault and attempted murder and elevated aggravated assault for shooting her son, Mathew Day.

Justice Robert Murray said during the 45-minute sentencing hearing on Wednesday morning that Gilday’s actions during the day leading up to the shooting on Aug. 28, 2013 – going target practicing with his shotgun and telling people that he was going to kill someone – showed premeditation.

“The court cannot answer that question posed to it today of ‘why.’ It is inexplicable,” Murray said, speaking in the courtroom with members of Arsenault’s family and friends and Gilday’s supporters.

Gilday pleaded guilty under an agreement reached by his lawyers and a prosecutor, Assistant Attorney General Leane Zainea, to avoid a trial that was scheduled for just weeks away.

Under the plea agreement, Gilday will be sentenced next month to 50 years for murdering Arsenault, who was 55 at the time, and 15 years for the attack on Day, now 23, to be served at the same time as the murder sentence.

Zainea said at the sentencing hearing that Gilday’s guilty pleas spared Day and another witness from having to relive publicly what they saw, heard and felt when they saw Arsenault murdered.

“A sentence of 50 years is going to remove him from society for a long time,” Zainea said.

No clear motive has ever been disclosed for why Gilday went to Arsenault’s home at 162 Waldo Ave. in Belfast and fired birdshot from a 12-gauge shotgun into Day’s arm and stomach, and into Arsenault’s shoulder and chest.

Day, then 22, lay bleeding on the kitchen floor but was able to identify Gilday as the gunman. He told police he didn’t know why Gilday had shot them, according to an affidavit filed in court last year by Maine State Police Detective Dean Jackson.

Gilday, dressed in a blue jail uniform with manacles around his waist and hands, answered only one question during the hearing, saying “yes, your honor,” when the judge asked him to confirm his identity.

He declined to speak when the judge gave him a chance to say something on his own behalf. His attorneys, Philip Cohen and Jeremy Pratt, also declined to speak when the judge offered them a chance.

Arsenault’s friends, Sheila Johnson and Greg Johnson, both spoke at the hearing and described being devastated by her death.

Sheila Johnson said that Arsenault’s last post on Facebook hours before her death said: “Forgiveness doesn’t excuse the behavior; forgiveness prevents the behavior from ruining your heart.”

“The jail sentence today may allow some of us to forgive and keep from ruining our hearts,” Sheila Johnson said, echoing what were some of her friend’s final words.

Greg Johnson said he had been texting messages with Arsenault shortly before her murder, had said goodnight and said he was “shocked” the next morning to hear she was dead.

“I just can’t understand why,” Greg Johnson said, facing Gilday in the courtroom. “Why would you murder someone you didn’t know? Why someone who is so innocent? She didn’t deserve to die.”

Members of Arsenault’s family also attended the sentencing hearing but did not speak.

No one spoke on Gilday’s behalf in the courtroom, but Gilday’s mother began yelling at Arsenault’s family members, friends and journalists as she walked down the stairs from the courtroom afterward blaming them for what happened to her son.

Outside the courthouse, the woman refused to give her name and told reporters to “rot in hell,” before others with her ushered her away on the sidewalk.

Zainea said that Gilday had texted with Day before the shooting expressing his anger and Day had invited him to his home to discuss why Gilday was upset.

But instead of knocking when he got there, Gilday fired his shotgun through the door when he got there, Zainea said.

“He went there to kill,” the prosecutor said.

Half an hour before the shooting, Gilday had been at his home at 30A Springbrook Drive in Belfast, dressed in a bathrobe and crying at one point when an acquaintance, Samantha Ladd, stopped to visit him.

Gilday told her he was going to “shoot some people tonight,” but answered only “I don’t care” when Ladd asked whom he was going to shoot, according to an account she gave to police.

Gilday has been in custody since the day after the shootings, when police arrested him at Penobscot Bay Medical Center in Rockport. He had been admitted to the center’s unit for psychiatric and addiction patients on Aug. 29 after telling the staff that he was a drug addict who “had taken a large amount of opiates the night before,” Jackson said in the affidavit.

A possible motive for the shooting could hinge on Gilday’s relationship with Day’s girlfriend, Misty Linscott, and her mother, Linda Linscott. Gilday drove Misty Linscott to report for a jail term earlier in the day before the shooting.

Misty Linscott told Jackson that Gilday was just a friend who would give her rides, that they had done drugs together but that they were not in an intimate relationship, Jackson said in his affidavit.

“She described Gilday as being a little strange. He would stare at her and make inappropriate comments to her in front of Day,” Jackson wrote.

Misty Linscott has declined several requests for interviews.

Linda Linscott told police that Misty had lost custody of her children to her, and that Gilday had become involved, helping Misty steal a camera from her with pictures that could be used to influence custody arguments, the affidavit says.

“According to Linda Linscott, Todd Gilday was upset because he seemed to think that she was trying to help the state take Misty’s kids away from her,” Jackson wrote.

The affidavit also provides detailed accounts from Day’s friend Jonathan Riley, who was in Arsenault’s house when Gilday fired the shots, and from a police interview with Day as he recovered at Eastern Maine Medical Center in Bangor.

Day told police that he considered Gilday a nice guy but “a bit odd.” He said he and Gilday acquired drugs for each other and Gilday gave him rides.

Gilday texted Day before the shooting, asking to talk to him about Misty and Linda Linscott’s custody dispute. Day agreed, but saw, when Gilday arrived at the house, that he had a shotgun with him.

“Mathew closed the door and tried to lock it, but Gilday shot through the door,” Jackson said in the affidavit.

Riley told police that he hid behind the couch in the living room but saw Gilday shoot Day, then Day’s mother as she came out of her bedroom, where she had been sleeping.

“Riley heard Mathew Day pleading with Todd Gilday not to kill them. Todd Gilday responded, ‘I’m going to kill everyone,’” Jackson wrote.

After the shootings, Gilday left the house and drove away, apparently without seeing Riley or firing another shot. Police found the shotgun on Sept. 1 in Levenseller Pond at the Searsmont-Lincolnville town line and traced it back to a Wal-Mart in Bangor, where Gilday bought it in 2012, according to the affidavit.