In an earlier case, the Massachusetts high court concluded that stun guns just aren't "arms" for Second Amendment purposes, because they didn't exist at the time the Second Amendment was written, and because they aren't usable in the military. In Caetano v. Massachusetts (2016), the U.S. Supreme Court unanimously reversed this judgment, holding that the Second Amendment wasn't so limited, but sent the case back so the Massachusetts court could consider other arguments.

Today's Massachusetts high court decision in Ramirez v. Commonwealth doesn't really much discuss the other arguments—e.g., the argument that stun guns are "dangerous and unusual," because they aren't common these days, or the argument that stun gun bans pass heightened scrutiny as public safety measures—but just concludes that,

Having received guidance from the Supreme Court …, we now conclude that stun guns are "arms" within the protection of the Second Amendment. Therefore, under the Second Amendment, the possession of stun guns may be regulated, but not absolutely banned. Restrictions may be placed on the categories of persons who may possess them, licenses may be required for their possession, and those licensed to possess them may be barred from carrying them in sensitive places, such as schools and government buildings. But the absolute prohibition … that bars all civilians from possessing or carrying stun guns, even in their home, is inconsistent with the Second Amendment and is therefore unconstitutional.

The bulk of the court's discussion focuses on whether the ban can be narrowed rather than invalidated outright, but the court ultimately concludes that it can't be narrowed:

If the Legislature had made it a crime only for this class of "prohibited persons" [referring to felons and certain other violent criminals, "persons who have been committed to a hospital or an institution for mental illness, alcohol, or substance abuse," and 15-year-olds] to possess a stun gun (or a comparable class), there could be no doubt that such a statute would be constitutional and that it would preserve much of what the Legislature intended through its broader ban. But we cannot ourselves limit the application of § 131J to "prohibited persons" without engaging in the "quintessentially legislative work" of rewriting State law. We would first need to decide whether the class of "prohibited persons" should be the same for the possession of stun guns as for the possession of firearms, which are more lethal than stun guns. We would then need to decide whether a person must be licensed to possess a stun gun, as is required to possess a firearm. And if we decided that a license should be required, we would need to consider if we should adopt the same licensing scheme for stun guns as exists for firearms, or some variant of that licensing scheme.

The court therefore left the statutory scheme in place for 60 days, to give the Legislature time to pass a replacement (though this particular charge against this defendant is being dismissed immediately).

By my count, this means that, since D.C. v. Heller, stun gun bans have been invalidated or repealed in Massachusetts, Michigan, Wisconsin, D.C., the Virgin Islands, Overland Park (Kansas), and Annapolis, Baltimore, Philadelphia, Tacoma, Anne Arundel County, Baltimore County, Harford County, and Howard County (all in Maryland).

Stun gun bans remain in effect, to my knowledge, in Hawaii, New York, Rhode Island, and Wilmington (Delaware), plus some smaller towns. The Hawaii and New York laws are being challenged in court. Stun guns are also heavily regulated (e.g., with total bans on carrying in most places outside the home) in some other places. For more, see this article, though the listing of restrictions in Appendix II is now out-of-date.

Disclosure: I've consulted a very little bit, through the Firearms Policy Coalition, on some of the stun gun litigation, and I was also involved pro bono in some such litigation through the Center for Individual Rights.