1590s, "slender riding whip," probably from a Flemish or Low German word akin to Middle Dutch swijch "bough, twig," or swutsche, variant of Low German zwukse "long thin stick, switch," from Germanic *swih- (source also of Old High German zwec "wooden peg," German Zweck "aim, design," originally "peg as a target," Zwick "wooden peg"), perhaps connected with PIE root *swei- (2) "to swing, bend, to turn."
The meaning "device for changing the direction of something or making or breaking a connection" is first recorded 1797. "The peg sense suits the mech(anical) applications" [Weekley]; also compare switchblade. These senses in English might be a direct borrowing from those senses in Continental Germanic languages rather than a continuation of the "pliant wand" sense. The meaning "a change from one to another, a reversal, an exchange, a substitution" is first recorded 1920; extended form switcheroo is by 1933.