I have my own opinion of course but I'd like to know the policy. Or at
least the SO communities opinion.
I think it's been well established here that there's no specific policy towards answers for homework questions so adhering to the help center's How do I write a good answer? would be the default. That is essentially it is up to you to decide and the community to judge as long as you at least pointed the asker in the right direction.
As far as the opinion part, I think it's a bit easier than you may be thinking. A good homework question shouldn't need an exhaustive solution. IME, a "good" student will say "I don't want the code..."; others may not but either way a question that requires a ton of code isn't really that good. IMHO, the question you linked to is not a good question in general. It's not much better than a requirement + code dump and a debug request. x-number lines of code doesn't quantify goodness.
When I answer this way I feel there is less of a risk that the student
will end up learning nothing or blindly copy the answer and get
accused of plagiarism.
This is beyond my concern in general. For one, that "risk" isn't mine; I'm more of a personal responsibility kind of guy. If a student doesn't learn anything that's unequivocally their fault - grappy professors and any other complaints included. And I surely am not responsible for someone's personal academic integrity. I'm a student myself, SO has helped me learn far more than it's hindered it; granted I no longer use it for homework specific questions.
Bottom line is when I answer a good question I judge it and answer how I see fit based on what I get from the post - attitude, effort, previous community activity, etc. And I answer a specific question, not debug their hundred lines of code.
You have the freedom to do what you will; do what makes you happiest and forget the rest is my motto and advice.