Baseball teams make trades for a variety of reasons. At least there are supposed to be reasons.
And baseball trades get evaluated in many ways, most of them way too narrow.
Most commonly, at least historically, are the fill-the-need types of exchanges. Team A needs pitching and has an extra outfielder, Team B needs an outfielder and has a spare pitcher. Win-win and all that. There are variations on that theme, some of them complex, but at heart it’s a case of filling immediate needs in an attempt to do better.
There are bad contract-for-bad contract trades that are less filling a need than getting rid of an albatross and hoping a change of scene will help whoever you get back.