There could be several reasons for somebody’s behavior or words, Understanding those reasons are essential to make a correct judgment (good or bad), having incomplete or incorrect information results in incorrect decision or judgment.
There's the saying:
Try walking a mile in someone's shoes.
According to UE, this idiom means that "you should try to understand someone before criticising them."
One blogger explained how that this expression is a call for empathy, which seems to fit the situation you ask about in your question. If we can understand the reason for someone's bad behavior, we might at least become more understanding as to why it took place.
The "reasons for somebody's behavior or words" to which you refer are called mitigating circumstances
As defined at freedictionary.com:
a circumstance that does not exonerate a person but which reduces the penalty associated with the offense
And in the same site's legal dictionary:
Circumstances that may be considered by a court in determining culpability of a defendant or the extent of damages to be awarded to a plaintiff. Mitigating circumstances do not justify or excuse an offense but may reduce the severity of a charge. Similarly, a recognition of mitigating circumstances to reduce a damage award does not imply that the damages were not suffered but that they have been partially ameliorated.
While the expression is primarily legal, it is used broadly in non-legal situations.
A man who carries a cat by the tail learns something he can learn in no other way.
To understand is to forgive
This is the standard English translation of the French proverb tout comprendre est tout pardonner (lit: "to understand all is to forgive all").
For a discussion of the proverb and analysis of the sentiment, see for example, Intimations by John D Barry, pp xiv or almost any freshman critical analysis of Billy Budd.