I believe you are asking if "mental work" is permitted on Shabbos where it leads to prohibited work after Shabbos.
The Shulchan Aruch, OH 306:8 states
הרהור בעסקיו מותר
thinking about one's work is permitted [translation mine].
However, in the very sentence, the Shulchan Aruch cautions that
ומכל מקום משום עונג שבת מצוה שלא יחשוב בהם כלל ויהא בעיניו כאלו כל מלאכתו עשויה
nevertheless, due to the Mitzvah of Oneg Shabbos, one should not think about these matters at all and should consider all his work as complete [translation mine].
This is true even when the thoughts themselves are not prohibited per se, as the Shulchan Aruch mentions previously in subchapter 1
חפציך אסורים אפילו בדבר שאינו עושה שום מלאכה
Business matters are prohibited even where they do not involve transgressing a prohibition [translation mine]
Hence, a distinction might be made between thinking about or planning work on Shabbos in order to do it after Shabbos and mentally working on Shabbos in a permissible manner and then after Shabbos deciding to continue those thoughts in a way that is prohibited on Shabbos.
Seeing as spontaneous singing is not prohibited per se (with the caveat that "instruments of noise" are not used*), it should not be prohibited on Shabbos. More so, singing on Shabbos is actually appropriate as the Psalmist said:
מִזְמוֹר שִׁיר לְיוֹם הַשַּׁבָּת: טוֹב לְהֹדוֹת לַיהוָה, וּלְזַמֵּר לְשִׁמְךָ עֶלְיוֹן.
A psalm. A song; for the sabbath day. It is good to praise the LORD, to sing hymns to Your name, O Most High translation
And the Radak explains:
יום השבת טוב להודות בו לה' משאר ימי השבוע כי האדם פנוי מעסקי העולם ונשמתו נח מטרדת הגוף ומתעסקת בחכמה ובעבודת האלהים
It is better [more appropriate] to praise God on the Sabbath day than the rest of the week because man is free from his worldly business and his soul rest from the restless of the body's troubles and deals with wisdom and the worship of God. [translation mine]
On the other hand, a professional music composer attempting to create material to be used after Shabbos or a layman who's singing extends to thoughts on how to arrange the music with instruments or other activities prohibited on Shabbos would seem to transgress the Shulchan Aruch above.
* The prohibition of השמעת קול, creating noise, is another topic