Im not an expert, and I'm rated lower, but as far as I can see, Rf8 or Rf7 both open up a new diagonal for the bishop on G7, of course, not immediately, but it lets your pieces become more active, and Rf7 gives a nice bonus of protecting your 7th rank just in case. But as I said, sometimes stockfish sees moves only a chess computer could calculate, and IF G5 is a bad move imo it's an inaccuracy at most.
Why is 14...g5 a bad move?

True Rf8 or Rf7 opens the diagonal but Rg6 also opens the diagonal and has the added benefit of creating a potential attack down the g file. And to be honest I find that in this line a lot of the time black eventually plays f4 followed by g5 as part of a kingside pawn storm and the center remains closed, making the diagonal not very useful anyway.
Rf7 protecting the 7th rank is a good point.
As far as 15. Nb5, Stockfish labels it an inaccuracy. From my perspective, it seems that after a6 white is getting no where with this move since the knight has to move back.

As a guideline, you don't want to advance to g5 as black because that's advancing one of your pawns in front of your castled king and that's usually to be avoided. This opening (King's Indian Defense) can sometimes justify pushing those pawns more than other openings, but it's still not without it's weaknesses.
Keeping things simple, it's not that g5 was so terrible in that position, but rather than ...fxe4 was the superior move for black because it opens up the f-file for your rook.

I played 14...g5 and went on to lose the following game. Stockfish considers 14...g5 a mistake. Instead it recommends 14...Rf8 or 14...Rf7. The position is relatively sharp and both Rf8 and Rf7 looks like a waste of time here to me when both sides should be attacking as rapidly as possible on opposite sides of the board. What is the justification behind 14...Rf8 and 14...Rf7 and what am I missing?
Rf7 is a common theme to protect against c7 invasion. Moving the R followed by Ng6 opens up the Q to h4 as well. My gut would have gone with f5 without calculations.

14...g5 is ill timed mainly because it weakens control of f5 prematurely.
The problem with it is 15.Nd2! and now Black is stuck regarding his kingside play:
15...f4 allows the problematic e2 bishop to be exchanged at g4, although 16.h3 first doesn't look bad, either.
15...Ng6 excludes the ...Nf5-Nd4 counterplay, and white will reply 16.exf5 and plant a powerful knight at e4.
So, Black is stuck, while white's play with Nc4 and/or a6 is very fast.
Since white has given up the dark-squared bishop for a knight, I believe that the best move would be 14...fxe4 15.Nxe4 Rf4 16.Qc2 Kh8 (or some other prophylactic move) because white's attack on the queenside has lost some speed.
IMO in this line Black has to play ...a5 at some time, e.g. 9.b4 a5, or 9.b4 Nf5 10.Re1 f5 11.a4 a5, or finally the line advocated by Gawain Jones 9.b4 Ne8 (it looks like a better square than d7 in these lines) 10.a4 a5.
I played 14...g5 and went on to lose the following game. Stockfish considers 14...g5 a mistake. Instead it recommends 14...Rf8 or 14...Rf7. The position is relatively sharp and both Rf8 and Rf7 looks like a waste of time here to me when both sides should be attacking as rapidly as possible on opposite sides of the board. What is the justification behind 14...Rf8 and 14...Rf7 and what am I missing?