Unknown, with various theories ranging from spontaneous usage as a nonsense chant, to less likely sources from Arabic, Latin, and Hindi.
Some etymologists suggest an origin from Arabic القَسَم (al-qasam, “the oath”).
alakazam
English Stack Exchange - Did ‘alakazam’ magically appear out of the thin air? (archived April 6, 2016)