I agree that f5 is irrelevant. A weakness is only a weakness if it can be exploited.
The main reason that g5 works here is that it can force the N away from f3, and then your N can go to d4 with not only a direct threat of Nxc2, which is VERY inconvenient to defend, and the more decisive threat of Nf3!. These threats are so strong that the computer thinks that Qd6 allowing Nf3 is best by two whole pawns.
It all comes down to forcing tactics that are favorable to black.
[FEN "r1b2rk1/pp4qp/2ppn1p1/5p2/7Q/1PNP1N1P/1PP3P1/R3R1K1 b - - 0 1"]
1... g5 2. Qb4 g4 3. hxg4 fxg4 4. Nd2 Nd4 5. Qxd6 Nf3+ $1 6. gxf3 gxf3+ 7. Kf2 Qg2+ 8. Ke3 f2 {Is crushing.}