gringo/a is a corruption of griego/a “Greek”
hablar en griego “to speak Greek” was code for “to speak in a language that is unintelligible”… so gringo/a meant someone who doesn’t speak the language (Spanish)
That’s totally a normal linguistic thing though - to equate language(s) with being gibberish.
In Spanish la barbaridad means “nonsense” but it has to do with the people of the Barbary nations, which was North Africa and the Middle East; places inhabited by the Berbers (the Barbary Coast etc.) So barbaridad was “the unintelligible language of the Arabic/Semitic Berber people” in a way.
And there’s also la torre de Babel or the Tower of Babel from the Bible. It was said that people were constructing Babel to make their way to Heaven. God saw this as an affront and struck the people with multiple languages of the world, making it impossible for them to work together and coordinate. From there, English has the term “babble” which is “to speak unintelligibly”.
Sometimes it’s not “stupid American” so much as “white foreigner”. It’s almost always pejorative, but there are other terms that mean gringo/a in other places.
There are other words for gringo/a like gabacho/a, güero/a and chele and they’re usually MUCH stronger than gringo/a in my mind. Especially chele which is a vesre (revés or “mirrored”) form of leche “milk”… so chele can “whitey” as in saying that someone has milky white skin in a mean way… or to be very vulgar since leche is vulgar slang for “semen” in some places.
…Much like fruits and vegetables, most Spanish-speaking countries have regionalisms for their slurs.