I'm a family lawyer.
I run a banner ad on TERB. Under the Family Law Act, both married partners have the right to stay in the matrimonial home. The only ways to over-ride that right are as follows: 1. One of the partners agrees, either informally or in a separation agreement, to leave; 2. A judge makes an order that one of the parties leaves and that the other gets to stay inthe house.
In actual fact, residing in the matrimonial home is tied up with who gets custody of the kids. The main criteria for a judge's "call" re who gets to stay is whether one of the partners is violent or "out of control" in some way and what are the best interests of the children.
If the kids have lived in the same neighbourhood for several years and are in the middle of their school years, a judge will often allow the parent who has gotten custody to stay and will hoof the other parent out. The residing parent may be made to financially compensate the leaving parent to some degree, depending on whether there's enough $ to go around.
(In actual fact, even without a court order, usually one of the partners cannot take living together anymore and "cracks" and moves out. It's all a matter of time.)