When I find that happening in a particular lick, I'll vary my grip on the string. Sometimes it means I need to grab the string on the part of my fingertip closer to my fingernail. When doing this, my finger will go under the neighboring string so it won't sound. Other times, I need to position my finger tip the opposite direction so the tip of my finger bends the string and also pushes the neighboring string up without sounding it.
I found it's when my finger nail hits the neighboring string through the bending motion that problems occur.
Other than that, it's something your hands and fingers kind of figure out on their own as you practice.