The honest answer to where "shenanigan" comes from is that nobody knows.
The word is American slang from the middle of the 19th century. Etymonline dates it to 1854 and quotes the Nevada Journal of August 18, 1854, which used the phrase "come the 'shenanigan'" to describe a political party's dishonest intentions. Merriam-Webster also gives 1854. The earliest uses cluster in California around the Gold Rush, in the San Francisco and Sierra Nevada region.
Some sources give a slightly later date, and World Wide Words dates the first print use to 1855. The wordorigins.org entry finds a citation from January 1855 in an Ohio paper and another in a California magazine from June 1855. Both put the word in quotation marks, which suggests the editors thought it was new. The spelling wandered for years, and World Wide Words counts about a dozen forms.
The theories fall into four groups.
The Irish theory points to sionnachuighm, "I play tricks," or to sionnach, "fox." It is plausible because many Irish miners were in the gold fields. A Spanish theory offers chanada, a shortened charranada, meaning a trick or deceit, which fits California's Spanish-speaking past.
A German theory goes back to a 1948 article in American Speech. It proposed the slang schinageln, "to work," and Schenigelei, "a trick." Etymonline calls this one less likely. A fourth idea is nannicking, an East Anglian dialect word for playing the fool.
Wordorigins.org is blunt about two of these. It calls the Irish and East Anglian ideas "just guesses, with no evidence behind either." Dictionaries mostly agree. Merriam-Webster lists the origin as unknown.
What can be said is how the meaning moved. The oldest sense is a devious trick used for an underhanded purpose. Today the commonest senses are questionable practices, as in political shenanigans, and high-spirited mischief, as in youthful ones.
The word even had a brief political detour. During the First World War, the Katzenjammer Kids comic strip was renamed The Shenanigan Kids in the United States, to shed its German name.