Superstition plays a big role in Twain's attempts to characterize people of the 1840's who are ignorant of the laws of science and nature. As human beings, we often look for reasons why something happens or an explanation for an event. We "knock on wood" to ward off bad luck and carry good luck charms to feel safe. Superstitions come from cultures where old wives tales are often embedded in a way of life that tries to explain phenomena. Although often coincidental, people will naturally make connections between signs they see and connect them to what happened after an event occurs. For example, if you start to notice that every time you wear a particular pair of socks, you hit a home run, wearing the socks will become a superstition you feel brings you luck.
In The Adventures of Huckleberry Finn, many of the superstitions come from the black culture in the novel. Jim believes in witches and a hairball that knows everything. He warns Huck that bad luck will come because Huck handles a snake skin. He believes that shaking out a table cloth after sundown will bring bad luck as well. Huck believes that when he kills a spider by flicking it into a candle flame, he is destined to have something bad happen to him. Ironically, Pap shows up and tries to claim Huck's money after the spider incident.
In the 1840's, people didn't know a lot about how the world worked. In order to explain and predict what could happen, they relied on superstitious beliefs to guide them and to warn them. Twain used superstitions in the novel to give an accurate, realistic account of what life was like during the time of his novel.