Some legal experts said the sentence seemed fair.

“It recognizes this is an aberrant crime, a juvenile crime, a crime of social media, of the internet, and of the unique dramas of teenage boys and girls,” said Nancy Gertner, a former federal judge and a professor at Harvard Law School. “It deserves punishment, but you have to put it in context.”

That context, she said, includes research and legal recognition that the adolescent brain is still developing at 17 and that spending any time in jail could be especially damaging to a troubled young woman like Ms. Carter.

Daniel Medwed, a law professor at Northeastern University, also praised the decision, noting Ms. Carter’s age as well as her own mental health issues.

“I suspect the judge opted for the house of detention rather than state prison to keep her close to her family and support network, given the emphasis that he placed on rehabilitation in his remarks,” Mr. Medwed said.

The case raised thorny questions about whether Ms. Carter could be considered responsible for Mr. Roy’s suicide — especially because she was far from the scene and had not provided him with a weapon.

But Ms. Carter had sent Mr. Roy scores of texts encouraging him to kill himself. And on the night in question, after he climbed out of his truck as it filled with fumes, she talked to him by phone and, according to prosecutors and the judge, told him to get back in.

He did, and was found dead the next morning.

Ms. Carter’s failure to help him in that crucial moment — by calling the police or by urging him to stay out of the truck — was what led Judge Moniz in June to find her guilty of involuntary manslaughter during the nonjury trial.