Apparently, the idea goes back to Heraclitus. In his fragments B110, B111 we read:
"It is not better for men to get all they wish to get. It is sickness that makes health pleasant and good; hunger, plenty; weariness, rest."
In the more liberal (and, arguably, misleading) translation used by quote aggregators:
"To get everything you want is not a good thing. Disease makes health seem sweet. Hunger leads to the appreciation of being full-fed. Tiredness creates the enjoyment of resting."
For academic discussions of Heraclitus's view of values, see Kahn, The Art and Thought of Heraclitus, which links B110 to B111, and Neels, Heraclitus on the Nature of Goodness. On B111, he writes the following:
"This fragment asserts that, for three sets of opposites, one opposite of each set makes the other opposite both good and pleasant. But it is difficult to make sense of this concept. How could hunger make satiety a good thing? Even more difficult to understand is how sickness could make health a good thing. Health seems to be the sort of thing that is good all of its own. We might take Heraclitus to say that health only seems good and pleasant because of sickness. This would be easier to understand; if a person was never sick, their health would never present itself as particularly good and pleasant. But Heraclitus does not say that sickness makes health seem good and pleasant; he claims that it in fact makes health good and pleasant somehow. Thus we must make sense of how sickness can make health a good thing.
[...] Heraclitus presents his reader with three ‘good’ things: health, satiety, and rest. These three states of being are generally thought to be good things. But, on my reading, these three things are not good simpliciter. Rather, health, satiety, and rest are in fact good, but their goodness is goodness for. But for whom are health, satiety, and rest good? The answer seems to be the sick, the hungry, and the weary. I do not suppose Heraclitus means that health is good only for the person who is now sick. Rather, if we follow the discussion of the previous fragments, Heraclitus seems to be pointing out that the goodness of various things is dependent on a certain kind of respondent. If we follow that pattern, Heraclitus seems to be saying here that health is good for the kind of respondent who can experience sickness.
[...] The point, I take it, is that his reader might agree to the statement that health, satiety, and rest are good things, but Heraclitus wishes his reader to understand that they are not good in and of themselves (i.e., good simpliciter), but that their goodness is goodness for, that is, goodness for the beings who can be in the opposite states."