This has been puzzling me for quite a while. It was particularly concerning that I could not figure a rational explanation for this behavior.
I considered a bunch of old known reasons seen for similar posts in the past. Random mistakes, spam seeds, trolling, DDOSing, ChatGPT, faking proficiency at job interviews. None of these felt good enough. Such answers appear too frequently for random mistakes but too infrequently for DDOS. I have never seen them end with spam edited in. They look too bland for trolling. They look too irrelevant for ChatGPT word salad. They are too unreliable for job interviews - because interested interviewer will likely have a closer look into the answer and discover cheating - especially if gets some -1 while hanging in a resume. Etc
Only theory that came to mind to tick all boxes seems to be this. Some teachers probably incentivise their students for "successful" posting at SO - assuming that this indicates some verifiable proficiency level. Students probably show them their logged in profile with non-negative score answers and get additional grade points, something like that. Some particularly unscrupulous teachers may even accept minor negative score - "oh -1, that's probably some minor mistake, acceptable for a newbie SO user".
If you think of it, dumping random code snippets at random irrelevant questions makes a perfect trick for lazy students of such (equally lazy) teachers. Whole SO system is designed to let it leak through. Code dumps have solid chances to sneak through LA, FA, LQA reviews no matter how irrelevant - because none of usual deletion criteria matches. Voting down is also hardly an issue because given total amount of poor quality answers many (most?) would hesitate to inwaste their hard earned rep into downvoting yet another one.
Students willing to stay on the safe side may even create two accounts and dump two "answers" and show their teacher one that survived long enough at reasonably acceptable score like 0 or maybe -1.
This seems to be pretty much the same thing as we already see in multiple homework dump questions. Lazy students don't know what is a good quality post and neither they care. They just throw their stuff against the wall and see if it sticks.
Next question I asked myself, okay if it's much like homework questions - why does it feel more painful? After all, questions are more visible and there are certainly more homework dumps than such answers (and probably will always be), so what's up?
My guess is, here it is important that question downvotes are free unlike answers.
When I see a homework dump question, I just vote it down (maybe optionally voting close) and go on with my life knowing that system will take care of the rest - lower visibility, asking rate limits, roomba - and it's gone. It costs me just few seconds - somewhat annoying but no big deal really.
With such answers, there is nothing like that. I could spend all my 30 downvotes a day on these and all I get will be just lost 30 rep points. Soon I will lose enough points to get out of voting down privilege (even sooner I will get out of VtC privilege) and will be unable to do even that. Helplessness, I really don't like it.
Granted, approach with pinging 20K users explained in another answer would work, but it takes so much more effort compared to how I handle homework dump questions. And I doubt that it can scale well if (or rather, when) more students will learn to use such tricks.