It is difficult to pinpoint the origin of this term, but I was able to find some information. In the early 1900s, a pool hall hustle was called a lemon game and around the same time in
‘to hand someone a lemon’ was slang for "to pass off a sub-standard
article as a good one." Britain
The word lemon for substandard cars gained popularity in the 1950s with one of Volkswagen’s ad campaigns. Volkswagen used the term lemon to denote any car that did not pass their thorough inspections. This campaign was considered a huge success and because of this campaign the use of the term lemon for cars became popular. You can view the ad here.
Thank you Lauren for suggesting this word.