I'll usually get a a notion for a guitar riff while I'm doing something mundane, like mowing the lawn or driving alone for some distance. Unfortunately, it usually never blossoms into anything more than that.
Substituting lyrics is something that arises in a situation, when someone does something ridiculous, and changing the words to a song to suit the situation happens. My first year roommate at university was incredible at it, and gave us lots of laughs at each other. Weird Al Yankovic made us all smile with his re-writes, like his "The Saga Begins" using the music for Bye Bye American Pie:
ACOUSTICS: Cordoba D10-CE / LaPatrie "Concert" / Takamine GD30CE-12 / Norman ST30
ELECTRICS: EP Les Paul Custom Pro / Gretsch Streamliner G2420T / EP Thunderbird Pro IV bass
AMPS: Traynor YCS50 / Peavey VK212 / Traynor AM150T / Fender Rumble 150
EFFECTS: Boss ME-80 Multi-effects / Ibanez WD7 wah