One should not set pesukim (verses) to melodies that are liable to arouse improper thoughts in the hearts of their listeners. However, it is permitted to do so with a song whose words have been forgotten over the course of time.
Sources and Explanations
Even the poskim who permitted singing melodies of non-Jews with words from pesukim of Tehillim and the like said so only regarding melodies that do not bring a person to improper thoughts, Heaven forbid. But if they would arouse such thoughts in him, it should be forbidden. As Rabbi Chaim Palagi writes in Kaf HaChaim (siman 13): “If only the singers would be careful not to sing the kaddish and the kedushah to the melodies of non-Jews in a maqam (musical scale), for one who knows them will be brought to improper thoughts, and it is piggul, it will not be accepted, and its absence is better than its existence.” Certainly, what is said here is not only regarding kaddish and kedushah; rather, anything that brings to improper thoughts should be avoided. Likewise, the Divrei Chaim of Sanz (vol. 2, Orach Chaim, siman 17) forbade singing this way in the synagogue, and he writes: “For they come to lust after desire in the house of Hashem, in His holy courtyards, and to think about their vanities during the tefillah by means of love songs sung with trills. Woe to these fools, uncircumcised of heart, there is no understanding in them.”
The Chatam Sofer (Choshen Mishpat, siman 190) has already warned that an improper thought prevents the tefillah, and he writes: “We believe that any tefillah or praise and thanksgiving with which any [improper] thought becomes mixed, even about one’s own wife, does not ascend on high before Hashem, blessed be He, and is not accepted before Him. For this reason we separate the women from the men in the synagogue, by themselves, so that they will not come to improper thoughts during tefillah and the tefillah will be rejected, may Hashem save us, etc.” [See Sha’arei Orah by Rabbi Yosef Gikatilla, end of Gate 2, who elaborates on the subject of invalid tefillot, Heaven forbid. His words are also cited in the Shelah, Masechet Tamid, Perek Ner Mitzvah, in a gloss.]
Likewise, the sefer Arugat HaBosem (cited in Yechaveh Da’at vol. 2, p. 26, in the notes) forbade a chazzan singing words of holiness to the melody of lewd songs, lest the listeners come to think about them, for they contain obscene speech and every abomination.
However, Rabbi Ovadia Yosef writes there to permit it if, over the course of time, the words of the lewd songs have been forgotten. Rabbi Yaakov Hillel likewise concluded in his work Responsa Vayeshev HaYam (vol. 2, siman 7, at the end of the responsum): “Regarding melodies whose origin is in songs of non-Jews from tens and hundreds of years ago, where in our days none of us knows or recognizes their words and content, it is not within our power to forbid them according to the letter of the law. And even on account of the principle of ‘the power of the agent within the product’ (koach hapoel banifal), on whose account there would be room to be stringent, it is possible that it does not apply, since they have become sanctified among us over many years and the memory of their corrupt source in lewd songs has been forgotten, and they no longer arouse or bring to mind that ugly matter. Therefore it seems that there is no basis to forbid them. The main concern is only regarding the chazzanim of our time, that they not go in this crooked path of listening to lewd songs (of non-Jews or of Jews) and composing songs of holiness and tefillot to them. Included in this warning are also the band leaders at the celebrations of a chatan and kallah and the like, who breach all boundaries and conduct themselves with excessive lawlessness in everything relating to this. Whenever the singer or the listener knows and recognizes the lewd words, it is certainly absolutely forbidden. One who does not know or recognize them, and hears or sings those melodies when words of praise and tefillot are set to them, there is no prohibition according to the letter of the law; but on account of the principle of ‘the power of the agent within the product,’ the matter is ugly.” End of quote.
From the sefer “Shaf Veyativ – Laws of Saying Tehillim” by Rabbi Shay Tahan, Chapter 5: How to Say Tehillim and Precise Pronunciation, Halacha 23 (p. 80 in the print edition). Translated from the Hebrew original.
