http://www.phrases.org.uk/meanings/38500.html
First recorded in John Gay's Poems, New Song on New Similies, 1732
It's a mix of meanings - a cucumber feels cool (low temperature) when you touch it. Cool also means 'calm', which is the meaning of this idiomatic expression.