The story
From ass + hat, from the slang expression have one's head up one's ass, thus, wearing the ass as a hat. The term is extended to people who are clueless or bumbling, who don't understand what is going on.
Etymology from Wiktionary, CC BY-SA 4.0.