James Martin has explained possible strategic advantages for one side to trade a piece. But that raises another question: if trading a piece is favorable for one side, then it must be unfavorable for the other. So, why would they allow the trade?
In some cases, avoiding the trade may be bad tactically. Often, this is because a trade of a piece actually wins a tempo, not loses!
[FEN "r1bqkb1r/pppp1ppp/2nn4/1B2p3/3P4/5N2/PPP2PPP/RNBQ1RK1 w kq - 1 6"]
6. Bxc6 (6. Ba4 exd4) dxc6 (6... bxc6 dxe5) 7. dxe5 Nf5 8. Qxd8 Kxd8
The classical position from Berlin variation of Ruy Lopez. White bishop is attacked; if it moves, Black has time to deal with a threat to their e5 pawn, and ends up a pawn up. But instead the bishop captures the knight, in one move dealing with the threat to itself and forcing Black to answer. The tempo thus gained is well-spent capturing on e5.
On move 8, trading queens in itself benefits Black, as it diminishes White's attacking chances. But it deprives Black from castling, which is good for White. And avoiding it would cost White an important tempo. A combination of these three factors lead to the trade being the best move for white, while allowing the trade by 7... dxc6 is considered the best move for black.
In other cases, avoiding a trade is a strategic concession:
[FEN "4r2r/pp1k1ppp/2p5/3p4/3P4/2P5/PP3PPP/R3RK2 w Q - 0 1"]
There is only one open file for the rooks in the position, hence, removing one's rook from it will concede it to the opponent. Nether side really wants it, so the rooks will likely be traded.