This was contrary to the T&C of stackoverflow.
You agree that all Subscriber Content that You contribute to the
Network is perpetually and irrevocably licensed to Stack Exchange
under the Creative Commons Attribution Share Alike license.
The author granted a CC license whether or not they posted a GPL notice. If the author lacked rights to grant that license, the whole post is invalid. So either the GPL goes, or the post goes. So, it's legal insofar as, under the T&Cs of the site, posting the code granted the CC license, and so the GPL notice was misleading noise.
If the author not only added the GPL notice, but clearly stated that his or her intent was to dual-license both GPL and CC, then it would be reasonable, if kind of pretentious and noisy. But if the impression is that the OP is trying to avoid the CC license in favor of the GPL, it's no go.
Meanwhile, some legal experts apply de minimus to small software snippets. On the other hand, if the author is specifically claiming the snippet as a copyrighted work, it's probably not a good idea to pick a fight.