Sorry in advance for my incredibly amateur attempt to explain this. I have absolutely no music experience but I have noticed that one of the key to a catchy song seems to be this practice. More accurately, the catchiness seems to come from causing the listener to expect one sequence of notes and then surprising them with an entirely different set of notes.
In many songs, a musical pattern is established; a simple sequence of notes that is repeated multiple times.
Take the following sequence of notes. The listener "expects" another E but gets an F instead:
C D E C D E C D E C D F
Sometimes this is more complicated and the expectations are only violated based on what the listener expects, as in:
A B C A B D A B E A (down one scale)G F
In this case, the listener likely expects "A B F" but gets something different.
So, in summary: Is there a term for this idea of defying the listener's expectations, often by breaking an established pattern, in a composition?