Law of inheritance
The law is Agnatic Primogeniture, not Agnatic Seniority.
A Grandson by an elder son comes before a younger son in line of succession for a King.
If the elder son has no sons, the throne then passes to his younger brother.
We don't have anything in Targaryen history where King died and Grandson took the throne (Except when Jaehaerys I died and Viserys I took the throne) but we see that is the westerosi law, Agnatic Primogeniture. Lord Elmo Tully became Lord of Riverlands when his Grandfather died (His father had already died).
It goes like this:
- Eldest son
- Sons of Eldest son in order of their age
- Younger son
This Agnatic Primogeniture law is the reason why we have a Free Company named Second Sons. Second Sons don't inherit, so they join that mercenary company sometimes to carve their own fortunes. Viserys is a second son, so is Bran. Bran told Ser Rodrik that he will never be Lord of Winterfell because After Eddard that will be Robb and after him, Robb's sons.
What happens once the cup has passed?
So what happens if Viserys inherits the throne before Jon is born?
Regardless, even if Viserys took the throne, Jon would still be heir of his uncle until a son is born to Viserys. Jon's mere birth wouldn't cause Viserys dethronement but he would be an attractive option for Lords seeking to depose his uncle.
If Viserys becomes King, the succession line shall be determined with regard to him, not his father. So by Agnatic Primogeniture, Jon would still be heir to his uncle as closest male kin. But as soon as a Son is born to Viserys, Jon will go down in line of succession. Since Jon did not exist when his uncle was crowned and anointed Lord of the seven Kingdoms, he can't claim the succession was invalid. Or Perhaps he can, if he wants to press his claim but opponents will point out that since Jon didn't exist back then, the cup has passed and now shall pass to Viserys' brood.
That is however my speculation not canon as there is no such case in canon where an uncle took the throne while a nephew was in womb.
Closest example would be that of Torgon Greyiron the Latecomer. When his father Urragon III died, he was outside of Iron Islands. Iron Islanders choose their Kings via Kingsmoot. His brothers called a Kingsmoot without inviting their eldest brother. The Ironborn elected Urrathon IV Goodbrother as King.
When Torgon returned, he claimed that he wasn't there to make his claim so succession is invalid, as he was the strongest claimant. He successfully deposed Urrathon IV albeit with force of arms.
That's the closest possible example of a claimant appearing once succession is done. But Ironborn are different. Their laws are different. Greenlanders follow bloodlines instead.
This seems like a good case for a fourth Great council.
If the succession is unclear, a Great Council is convened at King's Landing where all Lords elect the new heir or King. There have been three Great Councils so far (Only two aimed at electing new Heir/King), which resulted in election of Viserys I and Aegon V.
Now let's assume everyone knew about Lyanna and Rhaegar and that she was pregnant and Lords decide to wait until their child is born (To determine the sex, if its a female, throne passes to Viserys in any case) and convene a council to elect the heir.
From the precedent of 3rd Great Council, it is clear that Lords prefer to choose elder uncles rather than infant nephews with better claims like they elected King Aegon V instead of his nephew Prince Maegor even though Maegor was son of Aegon's elder brother Aerion.
So in that case, Viserys would win most likely. But trouble here is, Lords feared that Maegor may have inherited his father Prince Aerion's madness, which lead them to turn to his uncles Aemon and Aegon. Viserys was known to be a frightened child, hiding behind his mother's skirts and prone to erratic behavior. Not to mention, Viserys was a minor himself unlike Aemon and Aegon who were adults. So in our case, Viserys is more like Maegor, so Lords might be inclined to choose Jon instead and form a regency council to take care of statecraft until Jon could reach adulthood.
But that will happen only if Viserys hasn't been crowned. If he were crowned, it would be up to him to convene a Grand Council on Jon's birth. If he doesn't, then line shall be established w.r.t him.
Real world closest case
We have a real world case. That is of Shapur II of Persia. When his father Hormazd II died, he was still in his mother's womb. His elder brother Prince Adur Narseh inherited the throne.
As a result of revolts and conspiracy by nobles against cruelty of the Emperor, Shah Adur Narseh was murdered, his second brother was blinded, third was imprisoned but escaped to Roman Empire. Bereft of any other option, Lords of Persia turned to the unborn Shapur II.
The crown of Persian Empire was placed on his pregnant mother's pudenda as per the tradition and throne was reserved for the unborn child. (That is disputed by some historians given that sex of the child could not be known and if it was a girl, she couldn't take the throne).
The unborn child would go on to rule for seventy years, longest reign of any Persian Emperor and become one of the Greatest Emperors of Persia.