I don't think this is a big mistake for Napoli, because Spalletti also wanted to leave.
Leaving after winning that trophy is far better than stay with club a few more seasons and failing to get the title. Maybe Spalletti also thought of this, as we know, there are several coaches who take the same way. Zidane for example, he came out as coach of Madrid after get the title, as far as I remember Rijkaard did the same (CMIIW). Of course going after get the champion title will get a positive impression.