I mean, assuming that you like your spouse, it's a perfectly rational decision to stay with them despite it being possible to make money by leaving them. It's economics-paper level sociopathy to suggest that "I could maximize my personal income by divorcing the person I love" is an action to be taken.
Indeed. Ask my ex-wife (an economist) how that worked out for her.
And is that universally true? Does it apply to all relationships, like parents for their children?
That only works if both partners have similar income, similar working times, and also split household work equally.
Most relationships are not like that, especially when kids are involved, but often even before that. So you often have one partner work more while the other takes care of most of the household. This leads to a situation where one partner is financially dependent on the other.
Marriage laws are supposed to protect the dependent partner in that case.
Child support doesn't last that long — just until the child reaches 18. And alimony stops if the spouse ever gets remarried (though of course some people dodge that by not technically getting married to a new partner).