Where does the saying "made from scratch" originate?
In order to get a broader history of 'from scratch', I checked the PhraseDoctor. He writes for "start from scratch":
'Scratch' has been used since the 18th century as a sporting term for a boundary or starting point which was scratched on the ground. The first such scratch was the crease which is a boundary line for batsmen in cricket.
John Nyren's Young Cricketer's Tutor, 1833 records this line from a 1778 work by Cotton:
"Ye strikers... Stand firm to your scratch, let your bat be upright."
It is the world of boxing that has given us the concept of 'starting from scratch'. The scratched line there specified the positions of boxers who faced each other at the beginning of a bout. This is also the source of 'up to scratch', i.e. meet the required standard, as pugilists would have had to do when offering themselves for a match.
Scratch later came to be used as the name of any starting point for a race. The term came to be used in 'handicap' races where weaker entrants were given a head start. For example, in cycling those who were given no advantage had the handicap of 'starting from scratch', while others started ahead of the line. Other sports, notably golf, have taken up the figurative use of scratch as the term for 'with no advantage - starting from nothing'.
For the term made from scratch, this blog writes:
This use of scratch derives from a line or mark drawn or scratched into the ground to indicate a boundary or starting-point in sports, especially cricket and boxing. That meaning of scratch goes back to the late 18th century. From there it came to apply specifically to the starting point, in a handicap, of a competitor who received no odds: "Mr. Tom Sabin, of the Coventry Bicycle Club, has won, during last week, three races from scratch." (Bicycle Journal, August 18, 1878).
It was later applied figuratively with the meaning "from nothing", and it was used thus by James Joyce in Ulysses (1922): "A poor foreign immigrant who started scratch as a stowaway and is now trying to turn an honest penny." Thereafter it was taking up in cooking once boxed mixes and prepared foods became widely available. Today it is a badge of honor to be able to say one made a culinary delight from scratch.
As the other two answers mention, "scratch" refers to sporting events. However, it was first used in terms of boxing and cricket after which the term was applied to races.
It appears the term "from scratch" can be earliest derived from foot races, followed by other sporting events. Where the starting line was literally scratched onto the ground. There is even mention of it being use as a term in for a golfer who does not have a handicap. Eventually "from scratch" took on the meaning "from nothing". Hence cooking from scratch meaning to start with basic pantry items, and not to use premixed goods.