Good question 😊
This was already asked on Meta.SE. But neither of the answers received many positive votes there, so I'll quote here, this comment, which received more votes than both answers put together.
While generally OK, I worry that giving someone an answer anyway can encourage bad questions. Knowing that a question is not good for Stack Overflow and will get closed should be a deterrent from asking it. Expecting that you'll still get an answer because people are nice will convince you to ask it anyway, even if you know it will get closed. – yoozer8 Apr 17 '13 at 18:43
Here are the official guidelines on comments:
When shouldn't I comment?
Comments are not recommended for any of the following:
Suggesting corrections that don't fundamentally change the meaning of
the post; instead, make or suggest an edit;
Answering a question or providing an alternate solution to an existing answer; instead, post an actual answer (or edit to expand an existing one);
Compliments which do not add new information ("+1, great answer!"); instead, up-vote it and pay it forward;
Criticisms which do not add anything constructive ("-1, see previous comments you scallywag!"); instead, down-vote (and provide or up-vote a better answer if appropriate);
Secondary discussion or debating a controversial point; please use
chat instead; Discussion of community behavior or site policies;
please use meta instead.
When should I comment?
You should submit a comment if you want to:
Request clarification from the author;
Leave constructive criticism that guides the author in improving the post;
Add relevant but minor or transient information to a post (e.g. a link to a related question, or an alert to the author that the question has been updated).
The guidelines are pretty clear: Answering in comments is not recommended for either open or closed posts.
So it is up to the site moderators to enforce it or not.