Interesting topic.
I always thought that the melody notes alone were the key to a solo. Simply, because most of the solos I like seemed to sound like “unwritten melody” that could have easily been a part of the the song melody.
I also used to think the pentatonic scale alone was the answer, then I found a solo for “Blue Eyes Crying in the Night” and it combined both E major and E minor pentatonic scales and it seemed to mimic the song melody.
So, it seems there’s lots of options. Melodies, scales , combination of scales/ modes, chords, and chord tones. It not an easy task. I’ve heard some solos where they just play some common licks that have nothing in common with the song .The notes used are correct but they are meaningless and don’t convey the feelings in the song.
Then there are songs with minimal melody notes to draw from. I think in those cases you need to tap into the emotions of the song. One song that comes to mind is “Comfortably Numb”and its first solo. The melody notes would never get you that solo. It seems like the Bm minor pentatonic scales make up the notes of the solo but it’s obvious that just having the right notes is not enough. The solo in that song ( for me) tapped into the emotions of the lyrics. The articulations used with those scale notes and the position played on the neck, in my opinion is what made that solo just right for that song.
One book I would recommend is “Soloing Strategies” for guitar by Tom Kolb.
https://www.youtube.com/watch?v=6kFvhCFzoF8
https://www.youtube.com/watch?v=_UXNSkg06VE