Being married to the king is not a legit claim? Honest question, as I do not know how that works in the GoT world.
No. The SHOW is clear on how succession works. The titles pass to oldest male heir and then to his oldest heir. It then passes to brothers if the chain gets broken.
Robert is king, Cersei is just his wife.
Joffrey next in line and any male children of Joffrey would be above his younger brothers.
Then Thommen since J died without kids
However, if J/T were bastards that breaks the chain of Roberts children and it passes to his brothers
Stannis would be king and his wife would be just his wife. Then Stannis's sons would be next in line before Renly. As Stannis has no sons it would pass to Renly and his sons. Since Stannis and Renly are dead Thommen is the only person alive in the Baratheon line even if he isn't really a Baratheon. If he dies without an heir the Baratheon line dies with him. His wife is just his wife, she is only queen as long as he is king. It's like being first lady, you don't become president and stay in the white house if the president croaks. The widow of a dead king is referred to as a dowager queen, she's out on her ass. Unless....
If the king/queen have an underage heir who is next in line to the throne, as Thommens son would be if he had one, and the king dies, the kid inherits the throne immediately. Since the kid is too young to rule on his own an appointed guardian would serve as regent. In GOT Robert appointed Ned as Joffrey's Regent because he didn't trust Cersei. If the King died without appointing a guardian, the surviving parent would presumably be Regent.
So Margaery is only queen as long as Thommen is king. If Thommen dies without a kid, Margaery is a dowager queen and is gone. She has no claim to the throne through Thommen. If she has a son with Thommen and Thommen croaks she can serve as Queen Regent until the kid comes of age. Then she's out and is only a dowager queen. She can never be the real Queen in her own right.