Wiktionary says, of "no good deed goes unpunished":
Beneficial actions often go unappreciated or are met with outright hostility. If they are appreciated, they often lead to additional
requests
It is Wikitionary's last interpretation that I am most familiar with. For example, suppose you send a generous check to a charity in which you have no interest because a relative of a good friend died. It is a charity that believes in sending "free gifts" to contributors who send them more than X dollars, which you did. They send you an object (so ghastly that you would be ashamed to donate it to a charity shop) as a token of their appreciation, plus they solicit you for further contributions for years afterward. No good deed goes unpunished.
This happens, really.
I'm not so familiar with the first definition, but suppose you are out for a walk, and see an empty plastic bottle (clearly tossed by a passing motorist) defacing someone's lawn. You go on their lawn to pick it up, and are accused of trespassing. No good deed goes unpunished.