It's superstition. It means if you knock on wood, whatever you just said has a better chance of coming true.
There used to be a game like tag, where if you touched the appointed tree before you were tagged and said something similar to knock on wood, you couldn't be tagged as you were home free.
The way we think of "knock on wood" probably originated from that... I don't know the expression's origin, but "knocking on wood" is something you do if you don't want to jinx something.
For example, if you were to say "The Red Wings will win the Stanley Cup", you would knock on wood to prevent a jinx.
It's just superstition.
Knocking on wood, and the spoken expression "knock on wood" or "touch wood" are used as a charm to bring good luck or to avoid "tempting fate" after making some boast or speaking of one's own death.
The expression is usually used in the hope that a good thing will continue to occur after it has been acknowledged. So, for example, one might say: "The rain looks like holding off, touch wood", or "Knock on wood, I'm much better now."
It is commonly thought that knocking on wood has been a superstitious action to ward off evil throughout history. Some believe it has to do with knocking on the wooden cross. Another explanation for this practice is the pagan belief that spirits (dryads) lived in trees. By knocking on the wood of a tree while making some sort of a bold statement, the speaker could prevent the spirit from hearing him and stop the spirit from interfering.
However, there is no evidence for either theory, and the superstitions have not been traced beyond children's games of tag of the early nineteenth century.
According to Steve Roud, the earliest documented references to "touching wood" are from 1805 and 1828 and concern chasing games like "Tiggy-touch-wood", where you are safe from being "tagged" if you "touch wood". Says Roud, "'Tiggy-touch-wood' was an extremely well-known game, and it is most likely that the phrase passed into everyday language."