Why are 黄瓜 (cucumber huang2gua1) called “yellow gourd” in Chinese?

Names for colors arose relatively late in human history and tend to be unique to each culture and are usually not loan words, the only exception being orange, which tended just about everywhere to be named for the fruit of that color, which is interesting, it’s probably the last of the colors identified in common human speech.
 
Meanwhile, color perception and psychology varies from culture to culture. So e.g. black is the color of mourning in the english speaking world because it reflect austerity, somber sadness, whereas white is the color of mourning in China, because the soul is purified of its’ wordly sins at death to be wiped clean and readied for the next incarnation. Red is likewise just about always an auspicious color in China.
 
As to color perception colors for blue and green are closest both visually and linguistically, and this is why Russian unlike all the other languages I know has 2 communly used blues cyaniy and goluboy. Everywhere else it’s just “blue”.
In China however 青 means BOTH green AND blue and in fact refers quite specifically to that changing flame between green and blue and thus is also the idea of change.
 

“Yellow” in Chinese means anything from light green to dark brown. 黄 is the image of a straw leather stuffed target OR the image of a person bearing a yellow jade pendant. Song script tends to combine different meanings and present one character by using more than one of the six methods, which is why many oracle bone pictograms become pictophones or ideograms by the time of the song script.
Purple in English likewise covers a very wide range of colors from a very “deep” red to a very “light” “pale” blue.
 
Recall also that fruits and vegetables change colors as they ripen. So that may also be a reason.