It’s a racial slur.
It dates back to either the Mexican-American war or the invasion of Mexico before WW1.
The Mexicans mocked Americans by calling them “Green Coats” - but with their accent it came out “Gringo”.
“The Mexicans mocked Americans by calling them Green Coats”
A theory. The one I heard was that English settlers migrating in Venezuela or some place like that sang a song called “Green Grow the Rushes”. To the locals it sounded like “Gringo”.
I thought it was because the American soldiers sang the song “Green Grow The Lilacs”. When legends disagree.