Snails live in a different environment than slugs (a snail without a shell - well, almost) and use the shell to retract into to conserve moisture. In dry weather they even seal the end off so can can stay in their shell for a long period. As you can imagine, moisture is a very important life sustenance requirement as this is used to lay down the slime surface so they can move.
Water snails obviously use their shells for protection and are more primitive on the evolutionary ladder.
Slugs live in damp places so don't need a shell but many have a rudimentary shell, even internally.