In Psalm 3 and 4 David is obviously in great distress. Many times he repeats his cry for help, “save me” or “hear my cry!”
How interesting, then, that in verse 5 David says “I lay down and slept”. How could someone sleep whilst in a state of such trouble and anxiety?
I laid me down and slept; I awaked; for the LORD sustained me. (Psa 3:5 KJV)
Again, in Psalm 4 verse 4 he is quiet on his bed, and in v8 he says “I will both lie down in peace, and sleep”!
Stand in awe, and sin not: commune with your own heart upon your bed, and be still. Selah. … I will both lay me down in peace, and sleep: for thou, LORD, only makest me dwell in safety. (Psa 4:4, 8 KJV)
Jesus did the same thing when he was in the boat on Galilee. He was in the same trouble as the disciples, being in the same boat, yet while they were anxious, he was calmly asleep.
And, behold, there arose a great tempest in the sea, insomuch that the ship was covered with the waves: but he was asleep. And his disciples came to him, and awoke him, saying, Lord, save us: we perish. And he saith unto them, Why are ye fearful, O ye of little faith? Then he arose, and rebuked the winds and the sea; and there was a great calm. (Mat 8:24-26 KJV)
So also with David. In his anxiety he called out to God. He meditated upon his knowledge of God, and realised that having asked his Father for help, he ought to believe in that help, because God had always helped him in times past. At the same time he wrote the words of these Psalms, he was probably still experiencing his problems, yet he had conquered his anxiety through faith. Therefore in Psalm 3v6 he says “I will not be afraid”, and in 4v5 he advises us: “put your trust in the LORD!”.
I will not be afraid of ten thousands of people, that have set themselves against me round about. (Psa 3:6 KJV)
Offer the sacrifices of righteousness, and put your trust in the LORD. (Psa 4:5 KJV)
Having realised these things, he could confidently say “I will both lie down in peace, and sleep; For you alone, O LORD, make me dwell in safety”.