Well I'll offer my theory, no idea if it's right.
Once upon a time, when our entertainment was less sophisticated, we used to fight animals against each other for sport. This was often done in a specific construction, commonly a hole. The village I grew up in had a strange shaped and rather deep pond called the "cockpit". If you hunt around quite a few English towns and villages had cockpits, the names of which linger. Whether chickens get a better time of it now is of course debatable.
I think it became a nickname for the "command" area of boats as they started to be enclosed, and eventually the accepted name. A small boat still has a cockpit.
And as aeroplanes appeared, we borrowed a great deal from mariners, including the gold bars on your shoulder. I think we also borrowed the term "cockpit".
Well that's my theory, for which I've no proof at all.
G