The writer is talking about situations where misery might have a positive outcome.
If someone is miserable as a result of doing a good deed, you should consider the misery a holy state, and not interfere.
If someone is miserable as the result of bad luck, you should pity them.
If someone is miserable as the result of doing a bad deed, you should consider the misery as part of the punishment for that bad deed. The last part means that a person who would cricitise a criminal who was about to be executed lacks empathy, and others would not think well of them.
Overall, the passage sounds like someone giving some (not very convincing) reasons not to help out another person in misery.