This is the modern Western interpretation of the Legend of Momotaro story and the more obvious references in the Shuten Doji myth cycle, which is almost certainly based on some sort of ethnic war around Kyoto. The latter is actually better-attested because the story of the oni of Mt. Oe could be cross-referenced to three local disturbances by the Emishi (teh ancestors of teh Ainu).
The problem is that, while both stories (and similar ones) may be disguised rewriting of real history where the Emishi and other indigenous groups were turned into the oni, the mythical creature itself predates these stories (and even their settings) by centuries. The earliest references to the oni actually came from mid-7th century tales that were written down in the early 8th century, and in those depictions the oni were just purely supernatural beings, usually depicted as human souls (and bodies) twisted by revenge or ethereal beings who commit acts of violence to avenge the spiteful in response to curses. You can see this earlier depiction in the kanji originally used for them: 鬼 (gui, pronounced ki in on'yomi). Since the kanji is borrowed from Chinese, the original oni must have seemed to the Japanese to be similar to the vengeful ghosts of Chinese tradition. However, the Chinese concept of ghost assumes a fully ethereal being, while in the Japanese conception, the ghost still had a physical body (which may or may not be the original human body). You can also still see this in the way the kijo (鬼女 - literally demon woman/female oni) is depicted, since this yokai got split from the oni clade really early. So, an original oni would have looked like a male kijo, basically. This is also why many early depictions of oni showed a man in noble court attire with a twisted face, mirroring the kijo who were depicted as a court lady with twisted face.
The modern oni (horned, sporting a club and wearing tiger loincloth) is an even more recent Tokugawa-era representation that is actually based on astrology. In Japanese astrology, the Demon Gate (鬼門 - gui men in Chinese, kimon in Japanese) where oni are said to come from is located between the constellations of the ox and the tiger, and its direction is called ushitora (ox-tiger). This direction is represented in the ox-horns and tiger loincloth of the "modern" oni. The club is borrowed from Buddhism's depiction of the asura.
Looking at the historical evidence, then, the oni didn't start out as a racist representation of the Emishi, or for that matter their Ainu descendants. Rather, it was a Japanese spiritual creature that originally resembled the Chinese gui, but was later borrowed around the 14th century to dehumanize the Emishi in legends and stories connected to their conquest and extermination by the Yamato court. Later as this history disappeared in the background during the sengoku and Tokugawa era, the oni regained its purely supernatural identity and we somehow ended up with cute horny girls sometimes in tiger-striped bikini.
Can I just mention that I really love the modern Netflix version of Lum? She da best!