1. If already fully committed to resigning, to extract some benefit for a few weeks in the interim. Say a conference junket, or deferral of some mandatory training.
2. If part of a powerful group, to extract a better deal from management. I know of some engineers at FAANG that blocked plans for downsizing of cubicles this way.
Work as if you will resign on completion; it will enforce a sense of responsibility to document business processes, code, contacts-you name it.
And where toxic processes or customers do exist, it is important to remember that you have the power to walk away.
I only tell them when I actually am
Until then? Why give a reason for them to get rid of me?