According to the Naval Institute book Naval Ceremonies, Customs and Traditions by William P. Mack and Royal W. Connell:

“In a British order in council in 1748, the relative rank was settled with the Army by dividing Navy captains into three grades. It was deemed at that time that any officer in command was entitled to the title of captain while in command, regardless of rank.”