Well, if a party has enough votes to pass such a law, it means that the majority of the society has no problems with that.
Conversely, if this hypothetical party had a secret agenda to pass the law when they get elected, but they kept this a secret until then... first of all they will probably lose of voters in the next election.
Also, they might find out that former immigrants do not automatically reward this behaviour in terms of votes.
I do not find this scenario particularly realistic.
Before: 5 million illegals or immigrants.
Party A passes law making them all citizens.
After: Party A always wins because large portion of the new 5 million vote for Party A