The true origin of the lemon is apparently shrouded in mystery; in the 1st century B.C., a Near Eastern priest was subjected to a great flinging of citrus, and there is controversy over whether the fruits in question were lemons or citrons. For many centuries (apparently), lemon trees were mostly grown as ornamental fixtures.
In the 18th century, James Lind discovered that lemon juice helped fight scurvy in sailors (Vitamin C is also known as ascorbic acid, and more acidity makes for more sour taste). At some point in this timeline, bath salts come into the equation, and then the popularization of lemonade. In short, though, lemons are sour because that's the way people want them to be.