In my experience I have never seen much to do with punishment for officers on 18th century warships. Crew obviously faced flogging and such for all sorts of offenses but I have never seen officers being depicted as having public punishments aside from a scene in a Hornblower episode where as a recently enlisted Midshipman he was tied to the rigging, though I forget the circumstances. Were officers given leniency for their behaviour while onboard? Could Captains face punishment aboard their own ships?
Also as a side note if officers were either seen as unfit for their job or wounded or killed in action were the regular crew ever allowed up the ranks to fill empty roles in the chain of command?
Officers (whether they were commissioned or warrant officers) would not be eligible to receive corporal punishment aboard ship. If they did something serious enough to warrant punishment, they would generally be arrested by being confined to quarters (at sea or ashore) until they could be court-martialed by a body of captains, which could be empaneled by an admiral or the senior captain available on a given station. The Royal Navy's Articles of War cover many of the possibilities that could be consequences of a court-martial. It's hard to generalize about this sort of thing, but officers could face consequences from being found innocent, to reprimanded, to dismissed the service, even up to being executed (as Admiral John Byng was after being convicted of cowardice).
I wrote more about Byng here previously:
and
If Byng were shot, as Voltaire quipped, pour encourager les autres, it certainly worked, as I think I've shown in the second link. Byng was powerful and well-connected, and (although his conduct was not as problematic) courts-martial could and did take action against well-connected men -- Hortatio Nelson's stepson resigned his commission rather than face consequences for his incompetence.
Does that help? Sorry if this is rambling.