In the first decade of the 18th century, Hungarians fought a very exhausting and, in the end, unsuccessful war to secede from the Habsburg Empire and re-establish their old kingdom.
That time, the Habsburgs were too powerful to topple.
However, only 30 years later, the Empire was crumbling, its former allies turning against it, and as Maria Theresa inherited her father's throne, France, Prussia, and Bavaria attacked her with overwhelmingly superior forces. Maria Theresa asked the Hungarians for help, and they agreed, crowned her as their monarch, and provided much needed assistance in the war which followed.
The events themselves are well known and well documented. What is not entirely clear to me, is the Hungarians' motivation. Why did they support her? What did they expect to achieve by that? This could have been the perfect opportunity to regain independence. They didn't even have to start another secession war, all they would have had to do is just stay home, don't intervene, and let Austria crumble by herself.
The Ottomans' strength was already declining at that time, so the Hungarians didn't have any strong enemies threatening them which they couldn't have faced alone.
The sole hint I was able to put together was that the Hungarian Catholic nobility might have feared the Protestant minority becoming too strong, and they wanted a dedicated Catholic ruling dynasty. However, had this been the only reason, they could have elected a Catholic ruler from among themselves; they did have the required legislation to do so, and there was more than one precedent in doing so. Also, although she later proved to be a strong Catholic ruler, she was only 23 years old at the time of her coronation, without any powerful mentor figure, and she practically went to the Hungarians begging them for support.