After Marie-Thérèse’ mother died, her father Philip IV of Spain remarried. In keeping with his parents’ tradition*, he married his niece. Their son became Charles II of Spain at the age of four. Charles II’s health was fragile and neither of his two marriages produced a child. He died at the age of 38 without an heir.
When Marie-Thérèse’ brother, the King of Spain died without an heir in 1700 the next in line to the Spanish throne was her son Louis*. As heir to the French throne, the Grand Dauphin would not be acceptable. No European power would accept the same person on the throne of both France and Spain. Equally the eldest grandson Louis would inherit the French throne.
Charles II’s will therefore named the Grand Dauphin’s second son Philip as his successor to the Spanish throne.* The 16 year old Philip had to renounce all rights to the French throne for himself and his successors.
The following year he married Maria Luisa of Savoy, the sister of his elder brother’s wife.
* Charles’ sister later married her uncle.
** This was disputed by Austria. Marie-Thérèse’ younger sister had married the Austrian Emperor Leopold. Both Marie-Thérèse’ and her sister had died. The dispute led to the War of the Spanish Succession.