There isn't really any explanation necessary. On JAG Captain Rabb left the JAG Corps twice, once to return to Naval Aviation when his CAG (commander of the air wing) recommended returning to JAG for his career and the other time to fly for the CIA. By making Captain there really isn't much of a move up or get thrown out career game left to play. Although Captains and Commanders are now being forced off active duty in real life
So sometime after making Captain and going to Europe as a JAG he again returned to aviation. And as we return to Harmon Rabb's story he is the XO, not the Captain, of an USN aircraft carrier. Most carriers having at least 4 Captains aboard now, the CO, XO, CAG, and Engineer for the nuclear power plant. And often another Captain on a task force Admiral's staff.
Now the question is since he made it to Captain why has he not been forced into the reserves after 15 years? The same would go for Colonel MacKenzie, the real or easiest explanation is that she retired. But real life is after all those exploits we saw on JAG means neither one of them would pass the political filter for flag, Admiral/General rank.