First of all, what is the word of God? We argue ignorantly about the Bible, if we think that the phrase always means a quote from God. It can, but not always. The phrase can refer to the person of Jesus (John 1:1-3). In another place we read that the word of God came to Abraham in a vision (Genesis 15:1) and then quotes that word. In that narrow sense of the phrase, the words in the Bible before the quote are not the word of God, or word from God and the words in quotes are. Yes, sometimes the phrase word of God can mean a quote from God.
However, the phrase word of God is also used in a much broader sense, as the word about God or even the word from God delivered through faulty people. For instance, the word of God spread (Acts 6:7; 12:24) meaning the Gospel message. That does not mean that everything that the Apostles said in their public preaching was infallible. Nowhere does the Bible describe itself from Genesis to Revelation as the word of God. It is a phrase that comes from tradition. Yet, after the 400’s AD when the New Testament canon was completed, it was completely appropriate to call the Christian Bible the word of God in that same very broad sense.
When we call the Bible the word of God, we are not saying that every sentence is approved as God’s final answer on a topic. The Bible is a book that sometimes records very raw human emotions and some pretty awful sins, which are elsewhere clearly shown to be wrong. We need to read the whole Bible before jumping to wrong conclusions about any isolated text. What God does allow though, is for us to come to him and express exactly how we feel on an issue, no holes barred, completely honestly and openly whether or not those emotions are totally clean and pure in his eyes.
So, why did the writer of the Psalm pray such a horrible prayer? We need to understand that this was a natural, human reaction to similar atrocities that had been perpetrated upon the Jews by surrounding nations. What the Psalm does is give us permission to express to God exactly how we feel, even though later in calmer moments, he will lead us to more righteous thoughts.