This is not authoritative but follows what I know about evolution
Ancient Forms and Defenses
When thinking about 'modern' animals like snakes (even though they're not really modern, and are very much unchanged for millions of years) it's useful to think about the even older forms of related animals.
My mind's eye goes back over early lizards and salamanders and toads in swamps hundreds of millions of years ago. And before them, to wormlike things, sluglike things, etc. And before them, to protozoa. And everything in between.
In this case, it seems highly plausible to me that in the huge give and take of evolution over all that time, that 'venom' or venomlike offensive and defensive weapons would be very common. In fact, they are very common in the animal kingdom -- frogs with poisonous skin, spiders, insects, snakes, jellyfish, etc. Probably worms and nematodes and so forth. Maybe even protozoa, amoebas, etc., that 'sting' each other, repel each other with the equivalent of very rudimentary toxins.
If you can picture all this, imagine the underlying genetics. This means there are genes in the genome that express venomlike characteristics, and they could be -- probably are -- very, very old parts of the genome. So the way I think about this, is that any given species (or family) has a potential and a relative propensity to express venomlike features. It could be that the characteristics that led to venom in snakes was pretty much already in place way way long ago, when life on earth was just sludge and mire and weeds and algae.
Let's take a side trip and think about how this could have started, and how it might connect with immunity. Life is chemical. Slight mutations in chemical makeup would endow an individual with slight advantages, if it repelled an enemy. It might have developed from digestive glands -- organisms need to digest intake food. So it seems possible that chemicals that developed as acids or similar to break down food, could have developed to be more noxious or toxic.
Obviously if an organism developed such a mutation, it would not live to reproduce if it was susceptible to its own 'venom'. Over millions and millions of years, and millions of 'failures,' it seems likely to me that 'venom' genes would become linked to 'immunity' genes. That is, families that had a high propensity to express venomous features, would likewise have a high propensity for immunity. I don't know this is the case, but we do know that in the genome certain gene groups are linked. Sometimes the organismal features are related, sometimes they're not.
Now think about delivery mechanisms. Skin, spit, spines, teeth, fangs..... Maybe an early salamander-like creature had very corrosive spit, that helped it break down its food, or maybe even strong enough to stun a small insect in its mouth. It would already have an 'immunity' to that effect. Over time, it could get more powerful, and the immunity would have to get more powerful too. But this could develop gradually. Then fangs could develop too, and the venom sacks could evolve from saliva glands or some other gland.
Everything in evolution develops from something that was already there.
The eye example is famous because creationsists argued that the mammal eye is so complex, with interacting lens, iris, pupil, humor, etc., that no one part of it would have evolved independently. Famously, they said, "Half an eye would be no good to any animal."
Biologists have now shown exactly how the eye evolved, and it's actually one of the most complete and spectacular stories in evolution. So there, creationists!
The part of the story that's helpful in thinking about the venom story, is the very beginning. If you think about the same amoebas and protozoa and ancient creepy-crawlies, if just one of them developed a mutation that permitted a single cell on the surface of the creature to be light-sensitive -- perhaps affecting the rudimentary nervous system in some tiny way -- conveying heat or a tingle or stimulating an electric impulse or a chemical reaction -- this would immediately be a HUGE evolutionary advantage for that organism. Any sudden change in light could mean an enemy is near. And the organism could move away to escape or towards to attack.
So very simple changes would be inherited through survival of the fittest, and eventually become vision.
Trick question: Why don't trees and mushrooms have eyes?
Couldn't plants develop light-sensitive cells on their surface just like critters? Sure. That could happen. In fact I think there are lichens that glow in the dark, and we know about flowers opening to the sun, and all sorts of light interaction with plants. But no eyes.
Because what is the point of 'seeing' if you can't move?
So it's kind of funny, but if you look from the standpoint of evolution, it's a similar question to the venom question: "How did snakes evolve venom and immunity at the same time?" "How did mammals evolve eyes and walking at the same time?" (One is not much good without the other.) So pretty much everything in nature can be looked at this way, and the same kind of question asked, and the answers are all similar, in their basic outline.