Wittgenstein did not make the statement that if "you cannot doubt a thing, you cannot know it" (at least, in any of his writings). He did, however, say the following in section 480 of On Certainty:
§480 A child that is learning to use the word "tree". One stands with it in front of a tree and says "Lovely tree!" Clearly no doubt as to the tree's existence comes into the language-game. But can the child be said to know: 'that a tree exists'? Admittedly it's true that 'knowing something' doesn't involve thinking about it - but mustn't anyone who knows something be capable of doubt? And doubting means thinking.
But to understand what he is saying here, it's important to take a step back. On Certainty begins with Wittgenstein's critique of G.E. Moore's (mis)use of the the word "know," and then continues on about doubt, certainty, belief, and other epistemological problems. Wittgenstein contends that doubting is a language-game; it is one that is acquired like other language-games; and, there are such things that cannot be doubted:
§391. Imagine a language-game "When I call you, come in through the door." In any ordinary case, a doubt whether there really is a door there will be impossible.
§392. What I need to show is that a doubt is not necessary even when it is possible. That the possibility of the language-game doesn't depend on everything being doubted that can be doubted. (This is connected with the role of contradiction in mathematics.)
§393. The sentence "I know that that's a tree" if it were said outside its language-game, might also be a quotation (from an English grammar-book perhaps). - "But suppose I mean it while I am saying it?" The old misunderstanding about the concept 'mean'.
§394. "This is one of the things that I cannot doubt."
There have to be grounds for doubting (circumstances or contexts of doubting); these grounds are not anything anyone decides, but are learned in the way that we learn to use other words in their proper circumstances ( On Certainty, §271):
§522. We say: if a child has mastered language - and hence its application - it must know the meaning of words. It must, for example, be able to attach the name of its colour to white, black, red or blue object without the occurrence of any doubt.
§523. And indeed no one misses doubt here; no one is surprised that we do not merely surmise the meaning of our words.
§454. There are cases where doubt is unreasonable, but others where it seems logically impossible. And there seems to be no clear boundary between them.
§455. Every language-game is based on words 'and objects' being recognized again. We learn with the same inexorability that is a chair as that 2x2=4.
§456. If, therefore, I doubt or am uncertain about this being my hand (in whatever sense), why not in that case about the meaning of these words as well?
§457. Do I want to say, then, that certainty resides in the nature of the language-game?
§458. One doubts on specific grounds.
§519. Admittedly, if you are obeying the order "Bring me a book", you may have to check whether the thing you see over there really is a book, but then you do at least know what people mean by a "book"; and if you don't you can look it up, - but then you must know what some other word means. And the fact that a word means such-and-such, is used in such-and-such a way, is in turn an empirical fact, like the fact that what you see over there is a book. Therefore, in order for you to be able to carry out an order there must be some empirical fact about which you are not in doubt. Doubt itself rests only on what is beyond doubt.
￼But since a language-game is something that consists in the recurrent procedures of the game in time, it seems impossible to say in any individual case that such-and-such must be beyond doubt if there is to be a language-game - though it is right enough to say that as a rule some empirical judgment or other must be beyond doubt.
Even though doubt only arises in circumstances where doubting is possible, such a formulation is not tautologous. For, a “doubt that doubted everything would not be a doubt” (OC, §450). That is to say, if people were to say that “12 x 12 = 144” or that “water boils over a fire” are “perhaps (or probably) correct,” and then they go on to use these same words (perhaps, probably, and the like) with other propositions that most people consider indubitable, these sorts of people talk rather more about certain things than the rest of us; but “what difference does this way of speaking make in their lives” (OC, §338)? These riders are superfluous: it would be as if someone said, “I’m probably going to say something,” and then says that something. Since a child must be able to attach the name of its color to a white, black, red or blue object "without the occurrence of any doubt,” someone, who were to doubt whether that flower by the windowsill is red, should also doubt the meaning of his words—“red,” “flower,” “windowsill,” and so on (OC, §522). In other words, someone who doubts everything would not know what his words mean; he would not know what it means to doubt: Wittgenstein ponders if such a man is not more certain of the meaning of his words than he is of certain judgments: for, can he “doubt that this colour is called "blue"” (OC, 126)? Doubt stands in need of grounds; doubting and the grounds for doubting make up a system that is part of a world-picture: familiarity with what stands fast and what can be called into question allows for the doubting-game.
The grounds for doubt are interwoven in our world picture:
§185 It would strike [Wittgenstein] as ridiculous to want to doubt the existence of Napoleon; but if someone doubted the existence of the earth 150 years ago, perhaps I should be more willing to listen, for now he is doubting our whole system of evidence. It does not strike me as if this system were more certain than a certainty within it.
That is, the man who doubted the existence of Napoleon, or the moon landings, doubts the particular certainties that lie within his world-picture. But the man who doubts the existence of the world 150 years ago doubts all the evidence, all the facts, that encompass our world: a world-picture is a whole system of evidence, and each piece of evidence supports and is supported by all the rest. This example is also similar to, say, a tribe or society that has an entirely different world-picture. It is easier to convince, or persuade, them to accept our system than it is to convince someone who learned our system, and yet, is uncertain of, or think he can doubt, what is fundamental.
Something, however, “must be taught us as a foundation,” and at the “foundation of well-founded belief lies belief that is not founded” (OC, §449, §253). It is this latter claim that helps illuminate how people come to doubt what many people hold as indubitable; or, on the contrary, how people come to believe what others hold to be unbelievable. Wittgenstein remarks that what “men consider reasonable or unreasonable alters,” and at “certain periods men find reasonable what at other periods they found unreasonable,” and vice versa; he then, however, asks, “is there no objective character here” (OC, §336)? How can someone both believe that water boils at about 100 degrees Celsius and that Jesus only had a human mother (OC, §239-240)? All the evidence—all experience—shows that all human beings have two parents. However, “Catholics believe…that in circumstances a wafer completely changes its nature, and at the same time that all evidence proves the contrary” (OC, §239). But then again, these beliefs, like the evidence against them, are facts of human life. People do believe that a wafer becomes the flesh and wine the body of Jesus, and yet, also believe that there is no empirical evidence to support these beliefs. For example,
§279 It is quite sure that motor cars don’t grown out of the earth. We feel that if someone could believe the contrary he could believe everything that we say is untrue, and could question everything that we hold to be sure.
But how does this one belief hang together with all the rest? We should like to say that someone who could believe that does not accept our whole system of verification.
This system is something that a human being acquires by means of observation and instruction. I intentionally do not say “learns.”
§105 All testing, all confirmation and disconfirmation of a hypothesis takes place already within a system. And this system is not a more or less arbitrary and doubtful point of departure for all our arguments: no, it belongs to the essence of what we call an argument. The system is not so much the point of departure, as the element in which arguments have their life.
So, a “world-picture” provides a way that people can use certain propositions to test other, often empirical propositions: the "truth of certain empirical propositions belongs to our frame of reference” (OC, §83). How does this frame of reference impress itself upon people? Well, human beings “learn first the stability of things as the norm, which is then subject to alterations”; and, when a child learns language, he learns “what is to be investigated and what not” (OC, §473, §472). These are the reasons why children do not call into question whether the cup on the table exists—even if no one is present to look at it (OC, §472). Moreover, children do not learn that books exist—“they learn to fetch books” (OC, §476). The game proves its worth. People learn this-or-that language-game because its function is its value. The game needs no ground (OC, §474). And, people learn the ordinary use of language, as they learn their ordinary motor functions, and it is unnecessary and unrealistic to imagine that different language-games prove their values because they are logically sound and have grounds. Rather as Wittgenstein puts it, he wants to regard
§475 [M]an here as an animal; as a primitive being to which one grants instinct but not ratiocination. As a creature in a primitive state. Any logic good enough for a primitive means of communication needs no apology from us. Language did not emerge from some kind of ratiocination.
That is not to say that logic is unnecessary—it is what gives life to arguments. Rather, it is important to show that the language-game is not reasonable or unreasonable, but it “is there—like our life” (OC, §559). In other words, the purpose of language-games is to accommodate human life-needs (and everything that they entail). An obsolete language-game is one that no longer serves a function.
Also, Wittgenstein is highly critical of Descartes (and the idea that anyone can doubt everything). Throughout On Certainty Wittgenstein attacks the armchair philosophers like Moore, Descartes, and others who lay claim to theories of "knowledge," "certainty," and so on. So, in one way, Wittgenstein's positions in On Certainty "originated" with Descartes, if this were to mean that W. is trying to quell the foolishness that is Descartes's epistemology.
And for the pain question. The ability to differentiate between different sensations relies upon using different—but regular—signs to indicate these different sensations. However, the signs people use to differentiate the sensations are, as other words are, taught and learned through training. Human beings learn sensations—for example, the perception of colors—through training. It is appealing to think that the color red impresses itself immediately on human sight, so that anyone would be able to see one and the same the color—and contrast it with others—without having learned the word “red.” How would this be possible if there were no sign that could differentiate between the color-sensation of red and the color-sensation of blue. For further reading on color-perception, see Progress in Colour Studies: Volume II. Psychological Aspects, “Colour Categories and Category Acquisition In Himba and English.” See the Philosophical Investigations sections 244-400s as well as last few sections of the Investigations.