I have done more than my share of this sort of thing, (I like to ANSWER ALL THE THINGS!) but I've largely attempted to stop. I found as I "calibrated" myself better to the community, I could do a better job of detecting what questions were likely to be closed, and I largely avoid trying to answer them.
A closed question is one that doesn't belong on the site for whatever reason - part of closing is saying "this question should not be answered" for one reason or another. Sometimes closure is a temporary thing so that a question can be focused or improved, but the ones you seem to be linking to are more the "off topic" type than the "needs improvement" type.
Closing requires 5 votes from community members with the close vote privileged, or moderator intervention. Sometimes questions are controversial, and sometimes it's possible to salvage a borderline question with a good answer. However, you're opening yourself up to controversy when you do so. You're effectively saying "I don't agree with the community's decision to disallow answers on this question."
Therefore, I'd say if you look at a question and you know it will be closed (it's clear from comments or from pending close votes that closure is imminent, it's off topic according to the FAQ, we have established Meta policy on the subject, etc) I'd suggest not answering it.
Also, as a general rule, don't vote to close a question (or flag it for closure) and answer it. This sends mixed messages - "I don't think this is appropriate for the site, but it should be answered" is a bad message to send.
When it comes to comments, I tend to feel like things are a bit more lenient. Sometimes you can help a person or point them in the right direction, even though the question is likely to (or is already) closed. Some are more wary of this approach than others - we don't want to encourage people to post questions that will clearly be closed on the hope that someone will answer it in a comment instead. The overall goal is to keep the site as on-topic as possible.
It's important to note that extended discussion via comments is discouraged. Frequently you'll find people inviting the asker to chat, where many of the "off-topic for the site" topics are discussed on a regular basis. This is a better way to handle things in many situations, since it directs the asker and any other users viewing the question to the proper place for such a question. The only downside is the rep requirement may keep first-time askers from participating.