I don't like this deal, but there are so many variables we don't know:
-First, its a good deal for the Leafs for the next 3 years. You should be getting 'peak' scoring Nylander for 2-3 more years. The problem is he may have been demanding the additional years so you had to give him the long term deal in order to 'keep the band together' for their prime window of the next 2-3 years (maybe 4).
-I personally would have traded him if those are/were his contract demands for 2 reasons: 1.) you fee up that cap space, what else can you do with it? you lose a GREAT scorer, but you might be able to replace him with a good scorer AND a guy who is a big time help on the blue line. Oh, and ADD to that what you get back in a trade. In theory, with that cap space you can sign a forward to replace him a very good D-man, AND get some prime assets/prospects in return, hopefully 1 or 2 that are near NHL ready so when they do crack the lineup they are on more team friendly deals.
-But the other side of the above point, what is is value on the trade market? It might not be equal to what he currently is. Is he a great player? Yep, but any team he gets traded to is going to have to sign him to a similar contact....that probably rules out a lot of teams who have other plans for their cap space and others that just dont' want to....so you MIGHT Have had a reduced trade market and have gotten a lot less back in return than we think might be available.