Here are some early instances of "walls closing in," from various Elephind searches of old newspapers. From Julia Pardoe, "The Headsman of Strasbourg," in the [Pittsburgh, Pennsylvania] Post (June 24, 1859), originally published in Episodes of French History During the Consulate and the First Empire (1859), by Miss Pardoe:
Mad[d]ened by the thought [of betrayal], the wretched woman became unconscious alike of fatigue and fear, and her only desire was to escape from the terrors which she was surrounded. She felt as though the roof of the vault, spacious and lofty as it was, became every moment more heavy and more near, and that, the walls were closing in upon her on every side. Human nature could passively endure no more. She started shrieked and fled.
From "Watchman, What of the Night!" in the Richmond [Indiana] Palladium (February 2, 1860):
Again and again, of latter years, have I called to mind, when musing upon this subject [American slavery], the fabulous story of Vivenzio. He was immured by his enemies for some real or pretended crime within a spacious prison. Days and months passed away without his perceiving that anything unusual was taking place. He ate and drank and slept, and whiled away his time as best he could. At length he thought his prison had grown perceptibly smaller. Could he be mistaken? It was almost too strange for belief. He had seen no movement of the walls, heard no noise that might indicate such a thing. Day by day he sat and watched. It was no dream of the imagination. His prison grew smaller; the walls were closing in around him! They had been purposely so constructed that they might crush him to death by inches.—And thus it is with American Slavery. The walls are closing in around it and must eventually crush it to death.
From "Our Trip," in the [Springfield] Illinois Farmer (July 1, 1860):
From that point south we observe a change of soil for the better, and as the lake winds have faded away into other air currents, coming from the south and west, vegetation is much more advanced. The clearings along the line of the Lafayette and Indianapolis Road are small, and of recent date, and the heavy forest walls close in on the little way stations, giving them an air of seclusion that, were it not for the little ribbons of iron that connect them with the rest of mankind, might well account for their want of knowledge of the outside world.
From "Down a Freiburg Silver Mine," from the St. James Magazine, reprinted in the Wellsboro [Pennsylvania] Agitator (March 29, 1865):
Oh, that first ladder! I shall never forget the resigned feeling with which I stamped down step after step behind my guide; the greasy work; the damp, grave-like air;—above all, the roar and din from the huge water-wheels and engines constantly at work to keep the in enything looking order. Truly "I heard the wash of the waters, but nothing could I see"—save vast slimy boards moving slowly up and down at my elbows. At first I naturally enough took these collossal piston-rods for the firm walls of the chimney, down which I was creeping. I was set by one grazing my hip, and making me shrink within myself, like the man who saw the prison walls closing in around him.
The prison or crypt motif seems to be a recurring on in most of these early instances. One classic story in which prison walls close in on a prisoner is Edgar Allen Poe's "The Pit and the Pendulum," 1842) in which a prisoner of the Inquisition was subjected first to a razor-edged pendulum gradually being lowered toward him as he lay bound in ropes, and then by a yawning pit in the middle of his chamber, and finally by the heated, moving walls of the chamber slowly coming together and forcing him toward the aforesaid pit. Poe never refers to the walls as "closing in," however, although he does end with this image:
There was a loud blast as of many trumpets! there was a harsh grating as of a thousand thunders! The fiery walls rushed back! An outstretched arm caught my own as I fell, fainting, into the abyss. The French army had entered Toledo. The Inquisition was in the hands of its enemies.
But the Vivenzio story mentioned in the "Watchman, What of the Night" article from the 1860 Richmond Palladium is more than a decade older than Poe's story. From William Mudford, "The Iron Shroud," originally in Blackwood's Edinburgh Magazine (1830):
At last a horrible suspicion flashed suddenly across his mind, and he [Vivenzio] started up with a frantic air. 'Yes!' he exclaimed, looking wildly round his dungeon, and shuddering as he spoke—'Yes! it must be so! I see it! I feel the maddening truth like scorching flames upon my brain! Eternal God! support me! it must be so!—Yes, yes, that is to be my fate! Yon roof will descend!—these walls will hem me round—and slowly, slowly crush me in their iron arms! Lord God! look down upon me, and in mercy strike me with instant death! Oh, fiend—oh, devil—is this your revenge?
Mudford's story was widely reprinted in other periodicals and story anthologies, and the Wikipedia article on "The Iron Shroud" says that "The story is considered to have provided Edgar Allan Poe with the idea of the shrinking cell in his short story 'The Pit and the Pendulum'." Still, even if these stories did spark the popular image of walls closing in on a captive victim, the actual phrase "the walls were closing in upon" may not have appeared in print until 1859.