This psalm and many others were written by the Descendants of Korah. Korah was a Levite who rebelled against Moses in the wilderness where God caused the earth to open and swallow him and 249 other co-conspirators, but evidently Korah’s sons were not part of the rebellion.
In verses 1-8, the writer gave praise to God for how He led them out of Egypt and protected Israel during the wilderness travels. Then in verses 9-26, he asked why God had seemingly abandoned His people. There is no specific time frame mentioned, but it could have happened during the time of the judges when there was no king in Israel and everyone did what was right in his own eyes. It could have happened centuries later when the Assyrians were invading Judah and Israel, when the Babylonians invaded Judah, or even during the years between 400 B.C. and 73 A.D.
While the writer may have been truthful about his faithfulness to the Lord, many times God punishes a nation because so many people have rejected God from their daily lives. It only takes one generation to turn a Christian nation into a pagan nation. The only way out of these situations is for God’s people to pray continually for a national awakening. These situations have happened before in United States history. For reference, read The Light and the Glory by Peter Marshall and David Manuel, Revell Publishing.