جَاءَ الرَّجُلَانِ نَفْسَاهُمَا: dual emphasis is nominative with alif.
رَأَيْتُ الرَّجُلَيْنِ نَفْسَيْهِمَا: accusative dual with yāʾ.
مَرَرْتُ بِالرَّجُلَيْنِ نَفْسَيْهِمَا: genitive dual with yāʾ.
These are teaching examples. The referential pronoun humā stays the same; the dual case ending changes.