Raphael telling him about the agreement with Mephistopheles is the first clue he gets. Once he knows the name of the ritual he can figure out more while reading the Necromancy of Thay and there's a scroll with various rituals that Cazador put in Vellioth skull's mouth. If he doesn't come across any of that information it's a plothole that he knows which words to use during the ritual.