It was that way in WWII. I read a novel series set aboard a WWII US Navy destroyer where the Captain's rank is Lt. Commander.I'm not sure that has always been the case. Much of Star Trek is based on WWII rather than the post war period (because several people on the original production were WWII Navy vets).
It's not so confusing if you know how to recognize rank insignia.And it can be confusing because the CO of any ship is the Captain, regardless of rank.