You got the luck of the draw. It happens sometimes. It’s just funny as heck when it happens with Gief. It’s ultra mega super funny when you actually land a RBG, no less on someone’s ultra.
Here’s what happened:
You essentially grabbed him when Ryu’s invincibility frames from the ultra startup wore off. You can replicate this with anyone against Ryu with a jumping attack. In the case of the jumping attacks - usually the hard punch/kick kind with the longer start up frames - if you hit the attack before the ultra starts up (this is also height dependent), your attack’s active frames will come out after Ryu has let loose of the Metsu Hadoken and invincibility frames are no longer active. Your jumping attack will more than likely (badly) trade if this happens.
In this case, you grabbed him with a command grab. You lucked out on both spacing AND timing. I’ve done this same exact thing a few times myself - much the same as you, not on purpose (I’ll take the win though!). He jumped back, you ran forward to him and ended up at just the right spacing/distance to grab him as if he were to land and try to toss out either a s/c.lp. If he would’ve tried to toss out a s/c.lp attack instead you would’ve seen the startup of that punch, but you would’ve ended up grabbing him instead (same thing for a fireball, except no fireball would’ve been tossed out, you’d just hear Ryu go “hado!” then the powerbomb). The reason you lucked out on timing is that if you were just one step back/late, the Metsu would’ve pegged you as you came forward (well, you might luck out and absorb one hit > grab, but I’ve yet to see that). If you were too early, your grab would’ve whiffed and you’d eat full Metsu anyhow. You lucked out on distance in that you actually did move forward just a hair closer to Ryu as the Metsu was coming toward you. Those tiny in-game millimeters and milliseconds made all the difference.
If you want an easier way to replicate this, just to get the general idea of what happened, toss in Akuma vs Ryu in the training mode. Have Akuma sweep Ryu then do the Ultra Raging Demon (I’m sure the super works the same way, but the ultra lasts longer). On Ryu’s wake, do the Metsu. You’ll see the Metsu go right through Akuma and the Demon connects. Gief RBG is essentially the same thing, just way more difficult to pull out.