This is actually pretty common. You can think of it like playing a riff within the context of something else. In isolation, you can play it just fine, but when you play it around something else, it can get screwed up.

That's why it's so important to practice to backing tracks or metronomes and not just practice single riffs. Practice playing solos and riffs within the context of something greater. That way you can adapt to other styles, times, and musical contexts.

Yes to the above answer. You need to practise your licks in a context. Playing them individually and playing them within a song/ improvised solo is totally different. You've learned the licks; now learn how to implement them into your improvisations/ songwriting.

First, figure out which scale/ key they fit in. To do this you can either:

1. Relate them to a scale by looking at what scale shape fits in with the lick
2. Pick out the notes one by one, then compare those notes to scales built from the notes within the lick. (this can be tedious; I recommend the first method) (this 2nd method is made easier if you can identify which chords you could play this lick over)

I hope this helps!

Take it or leave it, the shadow is always there.
Holding your hand.
With a glass of ice cold lemonade in the other.
Listening to reggae music.
What more do you want?