The comparison between the final words of Hercules and similar words attributed to Jesus is mostly made in the translation. Ovid wrote his epic poem long before the rise of Jesus and Christianity; his words and their influence on literature were certainly drawn on by the educated scribes who wrote and translated the New Testament. This particular quote comes from the Agonies of Hercules, who inadvertently wore the poisoned shirt of Nessus. Hercules, having gone through many trials to prove his worth to the Gods, holds forth with a declaration of his many feats, and essentially complains that he does not deserve to be punished like this. Hercules claims that his many feats, done both for the good of mankind and for the glory of the Gods, makes him unworthy of this intense pain and suffering.
"But now a strange disease affects me that I cannot withstand by courage, weapons or strength. Deep in my lungs a devouring fire wanders, feeding on my whole body. But Eurystheus, my enemy is well! Are there those then who can believe that the gods exist?"
(Ovid, The Metamorphoses, poetryintranslation.com)
This line, in newer translations, seems to echo a quote from Jesus as he hung on the cross: "My God, why have you forsaken me?" The line appears in Mark and Matthew, and the sentiment is remarkable similar.
The explanation is, of course, that the writers and translators of the New Testament were familiar with the works of Ovid, since those works were massively influential on literature and poetry. Since, at their core, religious texts use conventions from both, the themes of a person empowered by God(s) being abandoned would cross over, especially considering how important the Crucifixion event is in Christianity. The comparison draws on themes of abandonment, fear, and disillusion, all of which are comparable in both works.
It cannot be said that the line was taken directly from Ovid. However, it is likely that the original text of the New Testament has been re-translated so many times that the original meaning may have been altered. Whether the sentiment was the same or not, the line remains both important and powerful. In the case of Hercules, it is because he feels that his life should prevent him from this sort of divine punishment; in the case of Jesus, it is because he was directly chosen by God to be his emissary on Earth, and in a moment of dispair he believes his suffering exceeds his destiny.