There are several reasons to it.
When your bowel movements are not good, if you are constipated, there you get too many negative thoughts. So purification of the body is a must.
When your digestion is good, then mind is clear too.
Second, you should do Pranayams. With Pranayama negative thoughts go away too. Third is, when you keep sitting all day doing nothing and there is not enough blood circulation is in the body, then also you get negative thoughts. To remove negative thoughts, do some exercises, or go for swimming, or for a long walk.
Exercise has a very good effect on the body and the mind. It improves blood circulation and negative thoughts go away from mind.
When the life force energy is low, do Pranayams and meditation. Satsang, good company, light food, all these affect our thoughts.
After doing all these, if negative thoughts still come, then just be a witness to these thoughts.