I think that was the best way he could have went out in that situation. A classic Nobara/Yuji combo.
Not only is that a great way to involve your female lead, if you're going to bring her back, but it was a big reveal. And lastly, Sukuna was still about to beat Yuji and the rest despite everything they pulled off, beyond exhausted all their options, Yuji evolved as much as he possibly could, and yet they needed one last trick to do it.
IIRC wasn't Nobara's death never confirmed? Even at the sight of her body, it was stated they will see what they can do but chances were slim. Her coming back was always a major possibility. Gege just dropped her in that dead people spread a couple chapters before her return to make it all the more surprising.