This lie is a kindness.
John already lost Sherlock, buried him, and never managed to stop mourning him. There was no getting over Sherlock’s death for John, even after two years, and I expect he never really would have got over it if it had been true. When he talks about Sherlock two years on, he looks just as broken as he did immediately after it happened. Sherlock’s death always stays fresh for him, even after he decides to move on. That’s a wound that wouldn’t ever entirely heal, unless Sherlock could do the impossible thing and do what John asked of him: don’t be dead.
The first time, he could.
So this time around, Sherlock knows he’s going to die for real, but keeps that fact from John. He lets John think that after his six months undercover, he’ll have some unknown, new adventure somewhere. And then another, and another. Swashbuckling his way across the planet, getting into scrapes and getting out of them again. Instead of John mourning Sherlock’s death forever, he could imagine him out there somewhere solving crimes, being brilliant, making the world a less dark place. He’d read about mysterious, amazing things in the papers and wonder if it’s Sherlock’s work. For the rest of his life he could image him like that, Sherlock the lone crusader, changing the world, unable to come home, unable to take John with him, but not for lack of wanting to, and not for lack of love. It’s just circumstances beyond their control. He’d be gone, but for John he’d still out there. Missing Sherlock is hard, but mourning him is harder.
Mary can tell when Sherlock is lying, but John can’t, and Sherlock knows it.
Sherlock now understands what his death would do to John. So he very kindly gives him something better.