Hi there,
Usually a composer use notes outside of the key of the song to resolve tension.
Hope this is correct :)
Have a great day