You're correct, it was originally a pit where cockerels fought.
The Oxford English Dictionary says:
a. A pit or enclosed area in which game-cocks are set to fight for sport; a place constructed for cock-fighting.
The first example is from 1587 in Thomas Churchyard's The worthines of Wales:
The Mountaynes stands..In roundnesse such, as it a Cockpit were.
So the author is comparing the towering Welsh mountains to a cockpit. This non-direct use suggests the term must have been in common use for its analogous use to be understood here.
From this barbaric sport, the term was later applied to a place where a contest is fought (1612); to a theatre (1616; appropriately the first-known example is by playwright William Shakespeare); to a part of a warship where the junior officers quarters were, and where wounded were cared for during battle; and finally, more familiarly, to aeronautics (1914) and motor racing (1935).