Psalm 22 in Handel’s Messiah

Charles Jennens, the text-selector of Handel’s Messiah, applied the agonies of Psalm 22 to Christ. Was he being sloppy with the Old Testament, or was he chasing down a thread of biblical theology?