This is an example of an invented explanation, because gringo was used in Spanish long before the war and during the Mexican-American War. Additionally, the U.S. Army did not use green uniforms at the time, but blue ones.
link
from what I read it comes from just not speaking spanish, or being a foreigner.
Although in mexico today it probably refers to americans mainly.
Well,ya know? The origin fer' the verbiaged terminology pertaining to that "gringo" word stems back to the Mexican American war of the middle/ late ,1840's (. picture in yer' mind's eye ,a 4.5 lb behemoth of Samuel Colt's walker dragoon revolver & you'd be about spot on / catching the 4th quarter of the time frame in question, anyway, it stems from a quite popular "marching ditty" the victorious American troops would all chime in& sing with great gusto as they were on the march thru out their defeated foe's former realm,,,as the spirited refrain went "
GREEN GROWS THE GRASS" and then the troops ,all in unison would stomp their right foot down extra hard on the ground,thusly sending up puffs/ plumes of dust that could easily be seen from a distance
( reckon it seared an indelible psychological scar on indigenous population that lives to this very day)
*TA-DA!!!*