Psalms generally are written not out of the particular experiences of their composers but for the various experiences Yahweh’s worshipers may face. Therefore, we should ask not, “Out of what circumstances was this psalm written?” but rather, “For what kind of circumstances is it appropriate?”
This prayer psalm of the individual uses language pointing to physical illness: “I am faint; O LORD, heal me, for my bones are in agony” (v. 2). It speaks of being near death (v. 5) and of possibly being bedridden (v. 6). Other features surface that are often associated with sickness in the OT: God’s anger and discipline (v. 1, which is identical to 38:1; see also 32:1–5; 39:8–13), and enemies and friends-turned-enemies who thus believe the sick person suffers under God’s judgment (38:1–22; 41:3–10). …