Context will show that this psalm was written by one of the Jewish captives in Babylon.
Jewish Study Bible: “This psalm is often recited on the 9th of Av, the day that commemorates the destruction of the Temple, and before the grace after meals on weekdays.”
Spurgeon: “In the later verses (7-9), we have utterances of burning indignation against the chief adversaries of Israel,—an indignation as righteous as it was fervent. Let those find fault with it who have never seen their temple burned, their city ruined, their wives ravished, and after children slain; they might not, perhaps, be quite so velvet mouthed if they had suffered after this fashion.”
Psalms 137:1 ¶ By the rivers of Babylon, there we sat down, yea, we wept, when we remembered Zion.
This verses confirms that the psalm was written by one who had been taken captive to Babylon. He remembers sitting on the riverbank among fellow captives and weeping over the destruction of Jerusalem.
Psalms 137:2 We hanged our harps upon the willows in the midst thereof.
Psalms 137:3 For there they that carried us away captive required of us a song; and they that wasted us required of us mirth, saying, Sing us one of the songs of Zion.
Indications are that the captives were treated well in Babylon because so many chose to stay there rather than go home when encouraged to do so at the end of the captivity. However, there are always those looking to mistreat the minorities among them. The fact that captives had instruments but were not making music did not go unnoticed. It seems that some of the native Babylonians taunted them, demanding that they sing the songs of Zion.
Psalms 137:4 How shall we sing the LORD’S song in a strange land?
The psalmist reflected that they could not sing about the LORD while captive in a foreign land. How could they sing songs of praise and thanksgiving while living as prisoners in a foreign land?
Psalms 137:5 If I forget thee, O Jerusalem, let my right hand forget her cunning.
Psalms 137:6 If I do not remember thee, let my tongue cleave to the roof of my mouth; if I prefer not Jerusalem above my chief joy.
The psalmist is expressing his love for Jerusalem from a musician’s point of view. He prays that his right hand will no longer be skilled (at playing the harp seems to be implied) and that his tongue will cleave to the roof of his mouth (so he cannot sing) if he forgets Jerusalem. He has a deep desire to see Jerusalem restored and the temple rebuilt.
Jewish Study Bible: “An oath never to forget Jerusalem. This is a central idea in Jewish tradition, enshrined in the liturgy, in the practice of leaving an interior wall facing Jerusalem undecorated or with a “mizrahΩ” (plaque indicating the east), and in the breaking of the glass at the conclusion of the wedding ceremony (which symbolizes, according to one explanation, placing the memory of the destruction of Jerusalem above one’s greatest joy, that of being wed).”
Psalms 137:7 ¶ Remember, O LORD, the children of Edom in the day of Jerusalem; who said, Rase it, rase it, even to the foundation thereof.
Edom = the descendants of Esau, the brother of Jacob; kinsmen of the Israelites
As he sorrows with homesickness in captivity, it reminds him of how the people of Edom mocked them as they were taken captive and shouted encouragement for the Babylonians to destroy Jerusalem. He wants God to judge them for their actions.
Ezekiel 35:15 “As thou didst rejoice at the inheritance of the house of Israel, because it was desolate, so will I do unto thee: thou shalt be desolate, O mount Seir, and all Idumea, even all of it: and they shall know that I am the LORD.”
After all, the LORD had publicly declared Jerusalem as the chosen place of His presence on earth.
1 Kings 11:36 “And unto his son will I give one tribe, that David my servant may have a light alway before me in Jerusalem, the city which I have chosen me to put my name there.”
Psalms 137:8 O daughter of Babylon, who art to be destroyed; happy shall he be, that rewardeth thee as thou hast served us.
Psalms 137:9 Happy shall he be, that taketh and dasheth thy little ones against the stones.
The psalmist is basically cursing the city of Babylon using very gruesome language. He is also blessing those who destroy her. I know he is talking about destroying the next generation to ensure their destruction, but I hate to hear language talking about killing babies in so gruesome a manner.
It should be noted that the psalmist was probably aware of the prophecies of Isaiah and Jeremiah that foretold the future destruction of Babylon.
Isaiah 13:19–20 “And Babylon, the glory of kingdoms, the beauty of the Chaldees’ excellency, shall be as when God overthrew Sodom and Gomorrah. It shall never be inhabited, neither shall it be dwelt in from generation to generation: neither shall the Arabian pitch tent there; neither shall the shepherds make their fold there.”
Jeremiah 51:24–26 “And I will render unto Babylon and to all the inhabitants of Chaldea all their evil that they have done in Zion in your sight, saith the LORD. Behold, I am against thee, O destroying mountain, saith the LORD, which destroyest all the earth: and I will stretch out mine hand upon thee, and roll thee down from the rocks, and will make thee a burnt mountain. And they shall not take of thee a stone for a corner, nor a stone for foundations; but thou shalt be desolate for ever, saith the LORD.”
Guzik: “Happy the one who takes and dashes your little ones against the rock: This awful blessing is understood in light of the previous line. No doubt the singer had seen this done to the little ones of Jerusalem, and the horrible image was seared upon his mind. He prayed that the Babylonians would get as they had given.”
Spurgeon: “We may rest assured that every unrighteous power is doomed to destruction, and that from the throne of God justice will be measured out to all whose law is force, whose rule is selfishness, and whose policy is oppression.”
Side note: Cities are often referred to in the feminine.