Weeping and being sad

The Messenger of Allah (sallallaahu alayhi wa sallam) visited Sa'd bin 'Ubadah during his illness. He was accompanied by 'Abdur-Rahman bin 'Auf, Sa'd bin Abu Waqqas and 'Abdullah bin Mas'ud (May Allah be pleased with them). The Messenger of Allah (sallallaahu alayhi wa sallam) began to weep. When his Companions saw this, their tears also started flowing. He (sallallaahu alayhi wa sallam) said, "Do you not hear, Allah does not punish for the shedding of tears or the grief of the heart, but punishes or bestows mercy for the utterances of this (and he pointed to his tongue)."

Sahiih al-Bukhaari and Sahiih Muslim

If tears flow from the eyes and there is sadness in the heart of a person but he is not angry at what Allaah has ordained for him and nor does he say something by means of his tongue or do something by means of his limbs which would be a sin and anger Allaah, then there is no sin upon him for the tears which flow from his eyes and the sadness which is in his heart.

This has been derived from the above Hadiith and others by the scholars.