He was a commander was demoted.
His rank was O-4, Commander, but he was the "Captain" (the skipper) of the submarine. Even an Ensign or LT-JG is referred to as "Captain" when they are in command of a vessel.
The rank of Captain (full-bird) is O-6, not always in command of a vessel.
The "Captain" of a carrier is usually an Admiral.