From an evolutionary perspective, this, that is, snails with clam-like shells does not appear too large a leap. A worm-like Aplacophoran produced a shell, so the hypothetical ancestral mollusk (HAM) developed it early in its evolutionary history. Most members of the Mollusca maintained a shell. The single flat shell condition that existed in monoplachorans was modified. Some members of that early mollusks formed a coiled shell (snails) or two shells (clams and mussels), and still others eight plates (chitons). Some members transitioned away from the shell, dropping or nearly dropping it (cephalopods). All this seems plausible.
Thus a snail with clam-like shells has maintained or activated the genes that allow that shell type—at the same time, heading in all other aspects toward the group that became gastropods.
There are other anatomical connections of this shell to other groups as well. Clam-like shells appear in arthropods: ostracods have them, and shell plates are a feature of most barnacles. This is a bit harder to envision, but not a huge leap.
A Monplacophoran, like Neopilina, may be similar to the ancestral gastropod.
Neopilina has a dorsal shell, a large flat foot, and tentacles, much like members of gastropods. Neopilina also has body segmentation like that of an annelid and arthropods. Although Neopilina appears to be a limpet, much more is happening internally (See figure below). Its internal structures, like gonads and nephridia, are similar to annelids. Along with the segmented body, the arrangement of the organs is in serial repeats, like the arthropods.
Parsimony
The scenario that is most likely is that the shell appeared at the point indicated by the purple arrow below: A feature is more likely to be lost in a clade than gained, so losing a shell is, in effect, easier than gaining one. So the most parsimonious explanation, the fewest large steps, is a Neopilina-like ancestor gaining the ability to make a shell. Some members of groups maintain the shell, while others along the evolutionary path have lost the shell.
Summary of the most parsimonious scenario:
The ability to create a shell, in any form, came early in evolution, the purple arrow. Then, since it should be easier to lose an ability than gain one, the genes for the shell are turned off (or altered) in many groups. Those groups that still had an active gene would have this gene undergo modification, two shells, more than two shells. The genomes of flatworms, annelids, and nematodes should have the genes, or partial genes, to create shells. These genes are inactive or have been modified enough to no longer function with that ability in many members. Do any of these groups still have members making shells? Is there a shelled annelid?
Note 1:
A phylogeny is a hypothesis; therefore, if the phylogeny above is incorrect, then the scenario suggested here may also be incorrect.
Note 2:
The early aplacophorans may have had 8 shell plates, like chitons, rather than a single shell, like the monoplacophorans.
Sources and Further Readings
Images are stolen from The Living World of Molluscs page:
https://www.molluscs.at/tryblidia/index.html?/tryblidia/main.html
Which took them from Biodidac
For a deep dive into shells, seek this one out:
Clark MS, et al. Lot of co-authors. Deciphering mollusc shell production: the roles of genetic mechanisms through to ecology, aquaculture and biomimetics. Biological Reviews 95 (2020) 1812–1837
Lemche H, Wingstrand KG. 1959. The anatomy of Neopilina galatheac Lemche, 1957. Galathea Reports 3: 9-71.
Sutton MD, Briggs DEG, Siveter DJ, Siveter DJ, Sigwart JD. 2012. "A Silurian armoured aplacophoran and implications for molluscan phylogeny". Nature 490 (7418): 94–97