David was not a stranger to rejection. In fact, since his first anointing as king he had experienced it. Beginning with King Saul, and continuing even through his own adult children, David had to learn to depend on the presence of the Lord for strength.
There were moments when it seemed that even God had turned away from David. It was as if David had been left completely alone to fend for himself, when all he saw before him were those who wanted to destroy him. It was at one of these moments that the fear and pain became too great, and he cried out to God in desperation: “My God, My God, why have You forsaken Me? Why are You so far from helping Me, and from the words of My groaning?” (Psalm 22:1)
This cry of David was not literally a question of where God was, but a heartfelt expression of the agony he felt because God had seemed to withdraw from him. Like a small child who has temporarily lost sight of their parent, David had temporarily lost sight of God. Intrinsically, David knew God was there, but he couldn't see His hand moving. David was not experiencing the deliverance that he had so many times before, and for a moment became troubled.
It was this same troubling feeling that Jesus Himself experienced upon the cross. When David vocalized his God-forsaken cry, it was prophetic of the cry that Jesus expressed in the darkest hour of His life.
Jesus had been beaten, scourged, mocked, spit upon, and nailed to a cross. But the physical pain was nothing compared to the spiritual emptiness He suffered the moment that He took upon Himself the sins of the entire world. The perfect Lamb of God had become the most sinful man on earth, bearing the weight of every sin of every individual who ever existed throughout all time. And as such, could not stand in the presence of God. For a time, God had withdrawn from Him so that the Person of Jesus Christ could take on the full wrath of God, including separation from Him. It was at this moment that Jesus cried out to God, feeling the broken fellowship between Himself and God: “And about the ninth hour Jesus cried out with a loud voice, saying, 'Eli, Eli, lama sabachthani?' that is, 'My God, My God, why have You forsaken Me?'” (Matthew 27:46)
Jesus was not literally asking where God was, but rather expressing the anguish He felt from being separated from His Heavenly Father. During His entire ministry, Jesus had been one with the Father, being the fullness of the Godhead in bodily form. He walked with the Father, moved in the Spirit, and proclaimed the coming kingdom over which He Himself was King.
It was a perfect union between God and man, one that God had intended when He created Adam. But at the entrance of sin, that union was broken. Jesus was the answer for reconciliation between God and man, but had to undergo the full separation so that mankind could experience that reconciliation. And while that separation between God and His Son was temporary, it paid in full the penalty for sin. Jesus endured this agony so that those who believe in Him will never have to.