1915, apparently from a language of the Philippines. Registered as a trademark in Vancouver, Canada, in 1932, the year the first craze for them began (subsequent fads 1950s, 1970s, 1998). The toy itself is much older and was earlier known as bandalore (1824). Figurative sense of any "up-and-down movement" is first recorded 1932. Meaning "stupid person" is recorded from 1970. The verb in the figurative sense is attested from 1967.
Let us cooperate; let us be reciprocally and mutually helpful: I'd love the whole country to get a good gander at how a labor union's supposed to run! You scratch my back, I'll scratch yours!
[1858+; scratch me and I'll scratch thee is found by 1704]