There was (and still is) a practice in cultures that practice polygamy that was referred to as "putting away" a wife. What this consisted of was basically kicking a wife out of your home. No means of support were given to her any longer. No food, shelter or clothing. Since she was legally married And the fact that women usually didn't hold jobs she had to either lie & get remarried or became a prostitute. Either way she became an adulteress. Some of the Pharisees at that time, during Jesus' ministry were practicing something akin to wife swapping while legally inside the confines of the Law. Today, as well as back then you could go to a marriage parlor and get married for an hour or two & then promptly divorced.
The Malachi passage which is famously partially quoted has a larger context which basically says in a nutshell that where God hates divorce He hates abuse more. And Jesus said that a woman's sin of adultery, who is a put away woman, would be held against her husband and not herself.
Also some guys would marry these "put away" wives knowing what they were. Jesus said they were guilty of adultery too.
And as well there was two camps of thought on divorce. One ultra conservative and one liberal. (They were trying to get Jesus to pick a side) and Jesus replied with a poetic, metaphoric answer about being not a child of God's. IOW apostacy was grounds for divorce and not any one particular sin. Which covers any logical reasonable reason for divorce and none of the petty ones. But does give license to those that have been left for petty reasons to remarry.
Jesus was anything but a legalist. To make him out to be one in one area of life is out of his character and simply scripture twisting for a personal agenda.