From the Italian 'scappare' - to escape.
This has been in use since the 17th century. Swell's Night Guide, 1846 includes the quotation:
"He must hook it before 'day-light does appear', and then scarper by the back door."
The word was adopted into the 'language' Polari and appeared as such in the now archaic phrase 'scarper the letty'. Letty is Polari for bed or lodgings.
Polari a.k.a. Palari, Palare, Parlaree etc. isn't a language as such, more a collection of words that have been derived from many sources - rhyming slang, backslang, Italian, French, Parlyaree (slang used by tinkers, beggars and travellers) etc. It could be seen as a secret code more than a language and has been adopted by various groups who have seen themselves as outside mainstream society. In the mid 20th century, when homosexuality was still illegal, the gay community in Britain used it extensively, although that was more for a feeling of solidarity than any real attempt to conceal what was being said.
Sometime after the military engagements at the British naval base of Scapa Flow in WWI and WWII a Cockney rhyming slang version 'scapa' was adopted, and this is how most people know the word today. It's easy to see how this would have migrated into rhyming slang from Italian/Polari, having the necessary pre-requisites of meaning go and rhyming with flow.