Feelings of schadenfreude are influenced by many different aspects including:
Festinger, L. (1954). A theory of social comparison processes. Human relations, 7(2), 117-140.
Lerner, M. J., & Miller, D. T. (1978). Just world research and the attribution processes: looking back and ahead. Psychological Bulletin, 85(8), 1030-1051. doi: 10.1037/0033-2909.85.5.1030
Pietraszkiewicz. A. (2013). Schdenfeude and just world belief. Australian Journal of Psychology, 65, 188-194. doi: 10.1111/ajpy.12020
Leach, C. W., Spears, R., Branscombe, N. R., & Doosje, B. (2003). Malicious pleasure: schadenfreude at the suffering of another group. Journal of Personality and Social Psychology, 84(5), 932-943. doi: 10.1037/0022-3514.84.5.932
Louis, W. (2014). Group Influence. In Myer, D. G. (Eds.), Social Psychology (287). North Ride, N.S.W.: McGraw-Hill
Smith, R. H., Powell, C. A. J., Combs, D. J. Y., & Schurtz. D. R. (2009). Exploring the when and why of schadenfreude. Social and Personality Psychology Compass, 3(4), 530-546. doi: 10.1111/j.1751-9004.2009.00181.x
van Dijk, W. W., Goslinga, O. S., Nieweg, M., & Gallucci, M. (2006). When people fall from grace: reconsidering the role of envy in schadenfreude. Emotion, 6(1), 156-160. doi: 10.1037/1528-.3542.6.1.156
https://en.wikiversity.org/wiki/Motivation_and_emotion/Book/2015/Schadenfreude
Schadenfreude is a complex emotion which can have many levels to it (van Dijk, 2011). It has many underlying concepts which relate to Social Comparison Theory, especially when evaluating the role of self-evaluation and schadenfreude.
There are many layers and reasons as to why we would feel schadenfreude, including biological factors, feelings related to envy, in-group inferiority, competition, Deserved misfortune, and personal gain can all contribute.
It is an emotion that can be considered very innapropriate and unsavory, however we all experience it, it becomes more about when to express it.
Learning about schadenfreude can help us understand why we experience emotions such as this and can help to become more emotionaly aware which can in turn help us improve our emotional lives.