I suppose it is the job of idioms to provide richness to the language by creating meaning that is different to the literal meaning of the idiom's individual words. Almost any idiom serves as an example - 'cloud cuckoo land', 'fancy-free', 'hat trick' and so on, but 'lily-livered' must seem especially opaque to non-English speakers endeavouring to learn the language. Why would that mean cowardly?
One clue is that our Middle Ages predecessors believed the liver to be in control of our emotions. It was thought to be the organ that created blood and that a poorly functioning liver was the cause of mental or physical weakness. Anyone who was choleric, bilious or irritable was labelled 'liverish'. There were numerous 'livery' conditions:
liver-hearted, or lily-livered - craven, cowardly
liver-faced - mean spirited
liver-lipped - pale and feeble
liver-sick - suffering from dropsy, or the diseases we now call cirrhosis and hepatitis.
By contrast, a robust liver supplying ample blood was thought to create rosy cheeks glowing with ruddy good health. References to 'ruddy' meaning 'healthy' date from the 14th century.
The second part of the explanation is that the lily was synonymous with whiteness. The White or Madonna Lily seems to have a whiteness that is whiter than other whites and the plant was grown in mediaeval gardens as a symbol of purity. In William Turners Herball, 1562, the author referred to it like this:
The Lily hath a long stalk... The flour is excedyng white.
In the same way as 'liver', 'lily' has been used as a prefix in several descriptive terms, in this case describing conditions that exemplfy purity or paleness - lily-cheeked, lily-fingered, lily-handed, lily-wristed and so on.
So, putting the two adjectives together we get 'lily-livered', that is, 'having a pale and bloodless liver'.
Shakespeare appears to have coined the phrase and, in Macbeth, 1605, when the Bard needed to emphasize the fear and cowardice of a servant who was bringing the king news of a military attack, he described the servant as 'a white-faced loon' and gave Macbeth the line:
Go pricke thy face, and over-red thy feare, Thou Lilly-liver'd Boy.