Something that strikes me when I read the Psalms is how often the words of a Psalm don't match David's actual emotions and behavior in the historical situation in which the Psalm was written.
For instance, in Psalm 3, David rejoices over the defeat of his enemy and how God has smitten his enemy's jaw and broken his teeth. But in the historical setting, David actually weeps and mourns the death of his enemy, Absalom - to the point of nearly losing the loyalty of his army.
Psalm 34 is written when David tried to hide in Gath by pretending to be crazy. Achish throws him out saying he has enough lunatics in his own kingdom, he doesn't need to import any from Israel. But when you read that Psalm, you'll see that the words don't match David's behavior or emotions in the least.
These are just two examples out of many that could be marshaled to make this point.
This is a striking demonstration of the Inspiration of the Psalms. The content was not dependent on David and his experiences. The experiences of David, as a type of Christ, served as a substrate for many of the prophecies in the Psalms, but this is not the same as saying that they explain them. The explanation – in other words – the actual source of the words, was not David, but the Holy Spirit.
This is where you can see the gross error of preachers who try to psychologize Bible characters and explain Scripture based on their feelings. It has always seemed to me that this method was an implicit denial of Inspiration because it looks for a naturalistic explanation for the content of Scripture. David did not provide the content of the Psalms – God did. These are the very words of God mediated through David and his experiences.
David was a prophet. The New Testament asserts this more than once. It was not an uncommon thing for a prophet's personal life to serve as a didactic tool or illustration of some theological truth. Think of Ezekiel being forbidden from mourning the death of his wife, or eating his famous (perhaps, infamous) bread. Think of Hosea marrying a harlot. Think of Jeremiah digging a hole in the wall of Jerusalem. These things were ordered and ordained by God in order to make a larger point to His people. In the same way, David's life was full of experiences which served as the substrate for the revelation God has given us in The books of Samuel, Kings, Chronicles, and the Psalms.