Considering that players who previously strengthened Napoli also left, and there was rumours that Napoli would sell other key players in the transfer market, this made Spalletti decision more unanimous to leave Napoli. As you said Leaving after winning that trophy yes is far better, because indeed him service that will be remembered by all people especially their fans rather than leaving when don't get any trophy, although there is still a possibility they will win again but maybe Spalletti doubts that.
If Spalletti himself has doubts about that, of course the fans will also doubt that next season, because with several new players and also a new coach at Napoli, there will definitely be a difference in Napoli's performance in carrying out the championship in Serie A. Because of the coach Different people will definitely have different ways and directions in organizing and providing strategies for their players so that the unanimous steps made by Spalletti were not wrong last season.