A Roman usurper takes over North Africa, a Roman emperor relocates to Carthage, or a Roman Emperor loses everything but Carthage, leading to a new kingdom being established. Alternatively, the Vandal kingdom lasts longer and makes compromises with the Roman nobility and Berber peasantry.
In any of these cases, it will become advantageous a few centuries later for kings/emperors/exarchs of North Africa to make an ex post facto justification for their rule and a national myth for the upper classes to follow. They'll naturally look to significant figures in the history of the city of Carthage, which will include Hannibal (for obvious reasons), and Caesar (not only as Roman leader but also as the rebuilder of Carthage), King Massinissa of Numidia (for his role in the Battle of Zama), Queen Dido, probably St. Augustine of Hippo, and others.
It's unlikely they'll ever forget about these figures if they retain any sort of literate culture, so it only takes an intellectual renaissance (which happened several times in the so-called "Dark Ages", the Carolingian renaissance and Macedonian renaissance for example) and national refiguring (in the case of crisis or an ambitious king) for these historical characters to be re-examined and placed into a national "identity". Even if this doesn't happen in an organized fashion, you'll see literati of North Africa making allusions to these characters, and if any of them happen to be great generals themselves, they'll definitely want to make comparisons to the great figures of the past like Hannibal. Eventually this will increase over time until there is a culture of referring to North African and Roman leaders.