Jesus was quoting Psalm 22 as He was on the cross.
Psalm 22 is a prophecy of Jesus' crucifixion. The rejection of the Messiah by the people (v.6), the insults they hurled at Him on the cross (vv.7-8 - compare with Matt.27:38-43), the pain of the crucifixion (vv.14-15), the piercing of His hands and feet (v.16), the dividing up of His clothing by lot (v.18) are just some of the more obvious parallels this Psalm prophesies. Jesus knew exactly what was going to happen to Him because He understood this Psalm and how it applied to His death on our behalf (cf. Matt.20:18-19). By quoting Psalm 22, our Lord makes this clear, and makes it clear to all who would later hear these words of His that He was well aware that He would have to die on our behalf in order to save us - for this reason He came into the world (Jn.3:16-17).
I found that explanation here: 'Eli, Eli, lama sabachthani': Why does Christ quote Psalm 22 from the cross? - Economy, History and Salvation - Monachos.net Discussion Community
That is purely a theory that he was quoting from Psalm 22...
controversial and strikingly different from some bible Versions, seem to be much more in accord with the principles and ministry of Jesus' life, since Jesus taught us to rise above the narrow confines of self-centeredness and self-pity in order that we may live every moment of our lives loving God and loving one another.
For some further insight into interpreting the words of Matthew, here is a brief summary of a rather lengthy article by Rev. Wayne Clapp who suggests that either the Greek or the Aramaic could be interpreted in an alternative manner:
There is probably no scripture more misunderstood than Jesus’ cry from the cross, "My God. My God. Why hast thou forsaken me?" Did Jesus Christ really utter these words? Would Jesus have accused his heavenly Father of such an act of desertion? Did God really abandon His only begotten son as he was dying on the cross?
The difficulty with Matthew 26:47 is due to an error in translation. "Forsaken" is the wrong choice for the translation in this verse.
"Eli" means "my God." Lama, or lemana means "why" or "for what purpose" and always introduces a question. It occurs 53 times in the Aramaic-English Interlinear New Testament (#1584) and it is translated "why" 45 times, "what" 5 times, and "for what purpose" 3 times. "Sabachthani" comes from sebaq meaning to leave, forgive, allow, reserve, or spare.
The Greek word translated forsaken, greek forsaken can mean to leave in the sense of forsaking and abandoning, or to leave in the sense of sparing or allowing to remain. The context determines the meaning.