The Naval rank of Captain originates from the much earlier term 'Post Captain' - appointed to the position (post) of Captain of a rated vessel and only Post Captains could command a rated vessel. They were considered senior officers and, because of their seniority, could not be dismissed or 'beached' like more junior ranks. Apparently the Royal Navy no longer calls every ships senior officer 'Captain' and they use ranks instead.
As to the story of Marine officers being brevetted to Major on board ship so as not to confuse the poor sailors as to who their real Captain was, I think that it's just apocryphal - the only place I've heard of it is in 'Starship Troopers' - not an accredited source!