It originates in a story from the Warring States Period (475-221 BC). One day after a ceremony offering sacrifices to his ancestors, a lord in the State of Chu decided to give a goblet of wine to his servants as a reward. However, there was not enough wine to go around (the Chinese might say, 僧多粥少, there is literally more monks than porridge).
One of the servants suggested a contest with the winner taking all. Each servant would draw a snake on the ground and whoever finished first would take the wine as the prize. One of them finished really quickly and decided that he had time to add some feet to his snake and still win the contest. However, before he finished adding feet to his snake, another servant completed their snake and won the contest. The first servant had lost the wine because he had tried to gild the lily by adding something superfluous to a picture that was already complete.