I know what the term means, just curious about the katakana spelling.
More specifically, オナニー is from German Onanie. Interestingly, German apparently borrowed the term from older English onania (per Duden's etymology here), which in turn was a derivation of the name Onan from the Biblical story mentioned by user Nothing at all. As a relatively recent non-native borrowed term, オナニー is thus written in katakana.
(Incidentally, Japanese learners quickly figure out the use of o- as an honorific prefix. Do not use this prefix when asking someone in Japanese, "what shall we do?")
It's derived from the Biblical story of Onan, which would mean its origin is foreign.