Why the Mavs do it: The Mavericks are just barely over the 2nd Apron. Niang makes less money than Martin while filling the same role. Niang is a worse defender, but the Mavs' defense is already good enough to compensate for that. Niang is also a better shooter and has winning culture.
Why the Jazz do it: Martin isn't too different from Niang and they get a free pick. The increased salary doesn't affect them that much.