Incharge tried to explain it, but I don't think he quite nailed it. A trade happens when both sides value the thing that the other side has more than the thing that they have. There are several players like Mercer around the league - young players who have established themselves as NHLers but have stagnated or gone backwards in their role and performance. A new team might think that a different role or different circumstances may help that player out. Or alternately, a team with an established player might want to deal him away for someone with more upside but whose recent performance is worse than the established player's.
The Zacha for Haula deal is instructive here - both guys had one year until UFA, the Devils wanted a veteran guy, Boston wanted to bet on upside. I think both teams were happy with the exchange.
Mercer wears a lot of hats for the Devils but my issue with him is that he doesn't do anything well. If the Devils could trade him for a 3C and then find a winger to replace him in free agency or trade, they could absolutely come out ahead.