Although size of tank does factor in you need to tell us the long-term living conditions and more details about the creature you want to put in the enclosure so that we can tell you if you can put it in there or not.
What kind of snail do you want?
I assume it's a mystery snail but I could be wrong.
The poster earlier probably has either ramshorn or pond snails as mystery snails don't reproduce without a mate of the opposite gender while other snails (ramshorn and pond) reproduce asexually.
The difference isn't only in reproduction though. there's also a massive difference in size and waste output.
Ramshorns and pond snails are small critters that put out waste but if you keep their numbers small it wont get too bad.
Mystery snails on the other hand ar BIG snails and produces a LOT of waste and ammonia.
Generally speaking unless you have a heavily planted tank (with STEM plants and fast growers. Moss, anubias, java ferns, and vals won't do the trick) that gets either a good two-three hours of direct sunlight each day ( or a 6,700 K(kelvin) bulb that's on most of the day) you really shouldn't put anything more than a betta in a 2.5 gallon.
A mystery snail would work in the 5 gallon if it were only the snail and the betta. And if the tank were already cycled or again heavily planted with stem plants that get adequate light to thrive.