First of all, the quote "Let them eat cake" is a mistranslation. The quote mentioned in Rousseau's Confessions is "Qu'ils mangent de la brioche" (Roughly "Why don't the eat brioche [instead]"). Brioche is a, in case anyone is unfamiliar with it, a type of bread enriched with eggs and butter but it is not a "cake".
Now, it is almost certain that Marie Antoinette never said this. Rousseau never attributes the quote to Marie Antoinette but to "a great princess". Second, if we are to go by Rousseau's Confessions, it was written before Marie Antoinette even arrived in France and before either of the two bread shortages under Marie Antoinettes time at court. Roussau finished Confessions in 1769, the two bread shortages under Marie Antoinette were in 1775 (The flour war) and in 1788. Rousseau finished Confessions years before either but did not publish it until 1782, after the Flour War but before the 1788 bread shortages. So, if we are to believe that Rousseau was in fact implicating Marie Antoinette in his work and perhaps added that part before publication it would have to refer to the 1775 Flour war.
So, while Rousseau's Confessions was likely the source of the quote being popularized during the french Revolution he never attributes it to Marie Antoinette. Possible candidates such as the daughters of Louis XV, Sophie and Victoire and the Duchess of Polignac have been proposed as the origin of the quote. Louis XVIII writes in his memoirs that within the royal family the legend claims it is from the wife of Louis XIV.
A further problem with attributing the quote to Marie Antoinette is that it seems very out of character for her. Marie Antoinette was many things. Perhaps vain, certainly extravagant in her lifestyle and very controversial but callous is not one of them. Now, relatively little written correspondance kept by Marie Antoinette survives today but from what does she does not come off as callous, neither was she described as such by those who knew her at the time. After the 1775 bread shortages she wrote in a private letter to her family:
"It is quite certain that in seeing the people who treat us so well despite their own misfortune, we are more obliged than ever to work hard for their happiness. The King seems to understand this truth"
This was a private letter, never intended for anyone outside her family. It seems unlikely that someone who displays that kind of compassion and dedication in private would publicly make such a callous remark.
So how did the quote come to be attributed to her?
Well, I'm not going to get into the causes behind the French revolution here. It's a topic entirely too long for a single post but suffice to say there was growing discontent among the public with a number of factors. The extravagant life of the court was one of them. In the years leading up to the french revolution pamphlets, writings, comdies and debates frequently portrayed the Queen as the leading cause of France's financial troubles. The charge was not entirely unwarranted. Marie Antoinette did enjoy a very lavish lifestyle and frequently financed her lifestyle in secret. This contributed to the troubles the various ministers of finance had in bringing the expeditures of the court under control. Outside of court she was sometimes refered to as Madame Déficit. More radical elements of the revolutionary faction also attacked her sexuality with everything from accusations of lesbianism to affairs with various members of the royal household and even an incestuous relationship with her son. All in all, the quote fit well with their agenda and as such was publicly attributed to her although it is very unlikely that she ever said it.
TL;DR - She never said that. It was attributed to her by the radical wing of the revolutionary movement because it fit their narrative.
Sources:
Marie Antoinette: The Journey - Fraiser A.
From the Austrian Committee to the Foreign Plot: Marie-Antoinette, Austrophobia, and the Terror - Kaiser T.