There is nothing in the psalm header which indicates the context of the psalm, but the editors of the whole Psalter may have intended it to be read along side of Psalm 3, a response to the rebellion of Absalom. While this is possible, there is nothing here which requires that reading. In fact, the opponent in the Psalm may not be specific enemies of David, b ut people who subject David (and Israel) to scorn because of their faith in God.
Craig Broyles pointed out several observations which can be made about these scoffers (Psalms, 52). First, they speak lies in order to shame David (vs. 2). Second, the opponent may be wealthy, since their new wine and grain abound (vs. 7). Broyles also points out that these Hebrew phrase “sons of men” (vs. 2, “people” in the ESV) is used for the wealthy in other Psalms (49:2, 62:9). Third, the opponents may have worshiped other gods (vs 6), the reference to new wine and grain is reminiscent of Baal worship in Hosea 2:8, 7:14.
While Broyles does not make any connection to a specific period in Israel’s history, from the time of David to the eighth century prophets there was a struggle between those who were completely devoted to the God of Israel and those who blended that worship with Baal. By the time of Elijah, for example, the northern kingdom of Israel worshiped Baal openly. It may very well be that Psalm 4 reflects the fact that Baal worshipers in the Northern kingdom were in many ways more successful and prosperous than those who worshiped God in the Temple in Jerusalem.
Verse 2 may be the key. The ESV reads “how long will people turn my glory into shame.” It is possible that this “glory” is not David’s reputation, but rather an allusion to God as David’s glory. Perhaps citizens of the Northern kingdom of Israel pointed out that since they were prosperous and Judah was not, God must be honoring them for their syncretic form of worship rather than the worship done in the Temple. After all, God is a just God and would not reward the nation if it was not deserved! From the perspective of history we know that the worship in the Temple the form God required, although even there the state of the heart of the worshiper was far more important than the outward method of sacrifice. To possess material wealth is not necessarily a sign of God’s blessing, to be in poverty is not necessarily a sign of God’s curse. In fact, it turns out that material, physical blessing cannot really be used to judge whether God is moving or not.
This point is a very applicable to the modern church. Some people will point to a large, wealthy church as think that God is surely blessing them, while the small church which struggles to keep the lights on is doing something wrong. In both cases, God may be honored, or God may be ignored. To use the material wealth of a church or ministry to gauge the health of a church is misguided. One only needs to look at examples of wealthy “Christian” organization which are led my men who are ungodly and immoral, or theologically suspect. For a ministry to “get rich” it is often expedient to ignore good doctrine and biblical morals in favor slogans and divisive issues.