After 2.f4:
2...Qf6 3.fxe5 Qxe5 4.Nf5 Rc7 5.Rf3 h6 6.Nd6 leaves White 2 points up with a killer knight on d6, and Black basically has no chances.
2...Qxg3 3.hxg3 Ng4 prepares to follow up with ...Re4, when Black is down a queen for a knight, but at least his pieces are active and the position is a bit blocked (for now).
It's still pretty surprising that Stockfish slightly prefer 2...Qxg3 over 2...Qf6 though. The neural net it uses for evaluation has a reputation of being more "intuitive" (compared to the hand-crafted evaluation from 2020 and earlier), and in a human game one could argue 2...Qxg3 may give slightly better practical chances. But still, 2...Qxg3 leaves Black down 6 points, compared to 2...Qf6 (where it's 2 points). It's curious that Stockfish does not prefer the materialistic route here, considering the material is so much more.
Perhaps when training the neural net, this style of evaluating gives elo gains, when applied to more balanced positions. E.g., maybe being a bit less materialistic gives elo gains to Stockfish, when in positions under 1.00. Then, this behavior of the neural net might still be used for positions where one side is completely winning (in your example, over +6), and whether this style of the neural net is completely optimal for these types of positions becomes irrelevant.
Stockfish will win any position over +6, and will lose any position under -6 (against a remotely comparable engine). So, it playing the strongest moves in such extreme positions doesn't affect how much elo Stockfish gains/loses, and thus wouldn't be a factor in what neural net is trained and eventually used. It should be noted that I'm just going on a tangent of assumptions here, but my main point is that if a neural net makes Stockfish behave slightly worse in totally won/lost positions, it likely won't affect the training of this neural net, and whether or not it's ultimately chosen to be used for Stockfish.
That being said, maybe 2...Qxg3 is indeed the better move from an objective standpoint. Not really any way to tell definitively.