In the times that Great Britain ruled the seven seas, British sailors used to entertain themselves with cockfights. The fight took place in a compartment below the deck nicknamed ‘The Cockpit’. Later, the term became to mean the ship’s steering bridge.
During WW1, the term “ascended” from the high seas to the high skies and became synonymous with the pilot’s steering deck.
Presently, it also describes a vehicle’s control panel.
Bonus Fact: speaking of cockpits, the origin of the term ‘Ace’ was coined in France during World War I, when air warfare began to develop. The first pilot to win the title of an Ace pilot was the French pilot Adolphe Pegoud. The French press called him l’as, “the ace” or “the champion”, after dropping five German aircraft in air fights.
Mind you, the term l’as was used in the pre-war French press as a nickname for sports stars. Hence, it was only natural that after it had been accepted for pilots, it also became a nickname for those who have won successes in other areas of the war, such as those who sunk ships or destroyed tanks.