In a narrow sense, we'll have traded Lafferty (at $1.15m) for Gregor (at $775k-ish) + a 5th rounder (the extra cap space also appears to give us the flexibility to have a 21-man roster rather than a 20-man roster).
That's a reasonable deal.
Now, assuming the Leafs staff would prefer Lafferty over Gregor in any notional lineup (it's ultimately pretty marginal, but a fair assumption), the trade was necessitated by our cap situation.
That then opens up the debate to whatever your bugbear is about the Leafs cap: the Matthews/Tavares/Marner contracts, Reaves at 3x1.35, Klingberg at 4.15, Kampf at 2.4, Leafs failing to anticipate Samsonov getting 3.55 in arbitration when they apparently were hoping to get him down to the low 3s, etc. Have fun with such debates as you like.
This cap thing is increasingly appearing to be an important consideration.