This is a joke that Mark Twain used more than once. When he satirically wrote of a callow private secretary answering the letters written to a congressman in “The Facts Concerning The Recent Resignation“, he had the fool recommend "Inflict soap and a spelling-book on every Indian that ravages the Plains, and let them die!"
In both of these cases, the joke is a comical exaggeration of conventional Victorian morality and historiography. In the late Nineteenth Century, when these stories were written, the people of Europe and America liked to think of themselves as modern. They had seen rapid technological progress that would have bewildered their grandparents. In Samuel Clemens's case, he had also broken free from some of the theocratic norms of his childhood. One tendency of these new moderns reading history was to consider the past as utterly backwards, promoting superstition, revelling in ignorance.
One of the conventional tropes to mark medieval thinking was that of uncleanliness. The Victorians had inherited "Cleanliness is next to Godliness" from the Reformation and read that as a reaction to supposed medieval dirtiness. This kind of thinking was bolstered by new scientific discoveries like Dr. John Snow's linking of the Broad Street Pump to an 1854 Cholera epidemic and Louis Pasteur's experiments in the 1860’s proving germ theory. There are multiple layers of irony here because in actual fact, medieval times were not as dirty as commonly portrayed, and Victorian cities like London were disgusting by today's standards with horse waste, thick smog, and diseased water being commonplace.
Nonetheless to the Victorian mind, especially among the educated classes, the root cause of medieval ignorance and superstition was the Catholic Church. The largely Protestant upper class, newly enthused with representative government, convinced itself that hierarchies (at least Catholic ones where they weren't at the top) bred servility, squalor, and ignorance. The thinking was that medieval people could have created canals, steam engines, and constitutions if they hadn't been constantly oppressed. I don't want to take the space to discredit this thinking here, but suffice it to say that the medieval era had plenty of very smart people and they weren't all engaged in futile debates like the proverbial "number of angels dancing of the head of a pin'.
In this Nineteenth Century intellectual environment, the connection between ignorance, Catholicism, and squalor would have been accepted as an axiom. This gave Twain, who always enjoyed pricking fallacies of snobs, an opportunity to exaggerate and satirize this attitude by touting soap as the cure for all social ills and as a stealth agent of modernization. Soap has been around since prehistoric times, but in the Nineteenth Century it became a packaged commercial product rather than something made in the home. It works as both a modern symbol and as contrast between the goals of the Connecticut Yankee and the surrounding medieval milliu. It functions in the quote above about American Indians in a similar way, a proposed "quick fix" to an ongoing culture clash that the Victorians would have seen as a fight against barbarism.
Needless to say, to both our eyes and to Twain, such a simplistic conception of culture is foolish. Neither the Connecticut Yankee nor the congressman's secretary are author stand-ins. They represent the eagerness of modern enthusiasts to solve social problems as easily as modern scientists and engineers had solved physical problems. This hope, running up against stubborn human nature and existing social systems, is the real theme of the novel.