There is a statue in Massachusetts called the Vacate Statute which is G.L. Ch. 208 Section 34b where a probate and family court judge can order a divorcing spouse to vacate the marital home for the need of the health, safety or welfare of the spouse that is looking to have the other party move out or for the minor child or children residing with the parties or would be a danger to be substantially impaired by a failure to enter into such order.
To have the court order that a party vacate the marital home, the moving party needs to prepare an Affidavit describing the negative conduct of the other party. The order can be on an emergency notice, meaning sometimes even without letting the other party be aware originally but then given the other party a follow-up hearing in order for it to be able to be contested. There can be criminal penalties if the order is not followed.