It's forbidden to think about Torah in the bathroom. Is it permissible to think about a song whose lyrics are Torah? If not, what about an earworm (stuck song) that you just can't get rid of?
R' Shlomo Zalman Auerbach quoted in הליכות שלמה (הלכות תפילה פרק עשרים סימן יא אות כא) ruled that there is a distinction between recital of pesukim in praise and song (דרך שבח וזמרה) and studying (דרך לימוד).
Singing pesukim is not considered limmud ha'Torah. Therefore, R' Auerbach rules that if one's mother, wife (who is not in niddah), daughter, or sister (even if she is married) is singing Shabbos Zmiros or Eishes Chayil (which includes pesukim), it is permitted to hear them sing while you are singing.
However, R' Auerbach rules that this distinction does not apply to ״מקומות המטונפים״ (filthy places).
See also the Sefer ואשי ישראל הערה צ״ו וק״ג
According to this, it would prohibit even the thinking of songs that include pesukim in the bathroom, as it is classified as a filthy place.
The implications of the ruling, however though are dependent on whether we really classify bathrooms today as filthy places.
So, what about today's bathrooms?
There is a major dispute among the poskim whether or not modern-day bathrooms are considered like the bathrooms of earlier times. Earlier-style toilets did not retain waste materials and were known as "parsoy."(Gemorah Brachos 26a, Rashi "d'parsoy"; Orach Chaim 83:4.) In present day toilets, the waste remains until it is flushed away. Nonetheless, many poskim say that our bathrooms are considered the same as the olden style bathrooms and one can be lenient in regard to the halachos that apply. (Minchas Yitzchok 1:60, Yechaveh Da'as 3:1, Ohr L'tyzion 1:1, 2:1:9, Shearim Metzuyanim B'Halacha 1:2:6.) However, most poskim argue.(Har Tzvi O.C. 1:50, Chazzon Ish O.C. 17:4, Igros Moshe E.H. 1:114,Halichos Shlomo Tefilla 20:24, Yabea Omer 3:2) Therefore, in case of necessity one can rely on the lenient view, but l'chatchilah our bathrooms do not have the status of the bathrooms of "parsoy."(Minchas Yitzchok 1:60)
[above paragraph copied from this answer]
So, if our modern day bathrooms are מקומות המטונפים (filthy places), then thinking of the songs would be prohibited. But if our bathrooms are not considered such, then it would be permitted.
(Note: Even according to the most lenient view, at the time that the person is defecating and the filth is present, it would be prohibited.)
Based on this distinction, Rav Chaim Pinchos Sheinberg זצ״ל was quoted as to have permitted boys to listen to Jewish music in the bathroom and shower.
Do not draw any practical Halacha from this answer. As per site guidelines, please ask your rabbi.