This occurred in GLX-MAS #1 published in 2005. It was a special holiday issue. The stories included are meant as parodies, and not canon within the main Marvel Universe.
Marvel describes the issue as such:
Marvel’s own Milwaukee-based Misfits are back—in their very own, double sized X-mas special! Sure, they survived the GLA mini-series, but can Squirrel Girl, Mr. Immortal, and pals survive… the HOLIDAYS?!? 6 all-new features of mockery, morbidity, and merriment-- including the return of Grasshopper, Deathurge… and the Yuletide tyranny of Dr. Tannenbaum?!
There are actually two stories involved here.
The first is "Eggnog, Toilet Paper, & Peace on Earth". It ends with Squirrel Girl running to battle Thanos.
The second story is "Days of X-Mas Past". Unfortunately, it is never explained how Squirrel Girl defeated Thanos, just that she did.
As to how Squirrel Girl might be able to defeat Thanos, one might refer to the answer to the question How did Squirrel Girl defeat Dr Doom? which explains a possible battle strategy (Squirrel Swarming the enemy with extraordinary numbers) and points out the fact that her official power/ability stats are maxed out.