Let's see. Your Rayquaza is probably a higher level than Groudon and Kyogre, seeing as you trained it. OHKO moves always fail when used against a pokemon of a higher level than the user.
Groudon's Solarbeam had to charge up due to Rayquaza's special ability: Air Lock, which nullifies any and all weather effects, meaning the sun is no longer there to power Groudon's Solarbeam.
As for the sleeping, it can vary from time to time how long the pokemon is asleep. Pokemon can be asleep anywhere from one to seven turns, so you probably just got lucky.