The main thrust of this stanza is that God provides comfort during times of suffering. In this passage, that comfort comes in the form of song. Take a look at this passage for yourself in Psalm 119:53-56:
When you are in the midst of suffering, your first response probably isn’t to sing. But Scripture makes the connection between the two more than once. God’s Word tells us that to sing when we face suffering, while not the logical choice we might turn to, is the choice we should turn to. The reason, perhaps, is that we can be more aware of God’s comfort in the midst of suffering when we sing.
The most prominent example of this perhaps is the account of Paul and Silas in prison, in Acts 16. The two were in Philippi, and had been severely beaten after driving a demon out of a slave girl. Paul and Silas were stripped and beaten, and then thrown into jail. Around midnight, they were singing and praying, drawing comfort from God for themselves, but also for the other prisoners who were listening to them. An earthquake occurred, and the prison doors were opened, leading to the salvation of the jailer before the night was over.
The fact that Paul and Silas were singing in the middle of the night, in the face of extreme suffering, mirrors Psalm 119 closely. The context of this whole stanza is focused on the persecution of the wicked upon the author, and the suffering he experiences as a result. But in verse 55, he remembers the name of the Lord “in the night,” just like Paul and Silas did.