The saying is a proverb that means it is possible to find some good aspect to every bad situation. The proverb is commonly said to someone who is facing a great difficulty and can see no positive way forward.
The phrase "silver lining" comes from John Milton's 1634 "Comus: A Mask Presented at Ludlow Castle." The phrase was used in conjunction with "sable cloud," which turned forth "her silver lining on the night." The words "cloud" and "silver lining" were collocated from that time. However, the full saying came into use in Victorian England. The Dublin Magazine printed the first use of the proverb while reviewing the novel "A Young Maid's Fortunes" in 1840.