What is the legal reasoning that 'allows' ending birthright citizenship?

From what I read, it is up to the Government to show the parents were NOT here legally. But I could be wrong. I think we all agree that the idea was stupid. Anyway from the questions posed by the Court, it seems they are not buying this. We shall see.