Here is what you need to know about the Secret ID:
From Generation III onward, there is a second, secret ID number, different from the visible one. This number exists purely to make sure that even if two Trainers share the exact same name and gender and the exact same Trainer ID number, the game will still recognize their Pokémon as coming from different Trainers. Usually, this number cannot be viewed; however, certain cheating devices can be used to view it, and there are also calculators to determine it. It also comes into play along with the normal ID number and the personality value in determining if a Pokémon is Shiny. If two different Trainers have the same Trainer name, identical ID numbers and identical hidden ID numbers (a 1 in 4,294,967,296 chance if the names do not differ), the game will recognize the two Trainers as the same, so the Pokémon are not considered to be outsider Pokémon.
TL;DR: It is used to differentiate between players. (even if they are playing the same gender, name, and Trainer ID)