It may come from the earlier "knocked for a loop", in boxing meaning to be hit in the head causing confusion.
(1922) "Kelley, the next time that guy comes back to my desk I am going to knock him for a loop!" exclaimed the Hotel Stenographer. —Logansport Pharos-Tribune (Indiana), 17 March, page 4
Google Ngrams shows "knocked for a loop" appearing around 1918, and "thrown for a loop" around 1945.
The Word Detective also places its origin at about 1920:
To be “thrown for a loop” or “knocked for a loop” refers to being bewildered, dazzled, disoriented and shocked by some event (“AT&T and T-Mobile were thrown for a loop last week when the Department of Justice sued to block AT&T’s planned acquisition of T-Mobile,” CNET, 9/5/11). The phrase first appeared in print in the 1920s, and comes from what the Oxford English Dictionary terms “a centrifugal railway,” but which is, no doubt, better known as a “roller coaster.” The “loop” on roller coaster runs is the point where the coaster arcs upward through a complete circle, leaving passengers upside down at its apex. The term was initially used in the literal roller coaster sense and then to describe aerobatic maneuvers by pilots “looping the loop,” and finally in boxing to mean a powerful punch that downed an opponent, before acquiring its modern “OMG!” usage.
Other sources disagree with the OED theory, preferring to link it to "loopy", which first appeared in the 1820's. The first roller coaster with an inverted loop was built in the 1950s.