Hello, I'll gladly answer your question.
The central Idea of it is to express understanding and comfort to the person that is going through a hard situation. However, this idea can change its intention according to the way it is said, the intonation used, body language, and more.
Due to the misuse of this expression, people often feel challenged by the other person when getting that answer.