This phenomenon is called hedonic reversal or benign masochism. It also covers enjoying any negative bodily reactions and feelings.
Hedonic reversals group, by factor analysis, into sadness, oral irritation, fear, physical activity/exhaustion, pain, strong alcohol-related tastes, bitter tastes, and disgust.
Liking for sad experiences (music, novels, movies, paintings) forms a coherent entity, and is related to enjoyment of crying in response to sad movies.
For fear and oral irritation, individuals also enjoy the body’s defensive reactions. Enjoyment of sadness is higher in females across domains. We explain these findings in terms of benign masochism, enjoyment of negative bodily reactions and feelings in the context of feeling safe, or pleasure at “mind over body”.
Related: What's a word for doing something eagerly despite the pain? Especially in the context of eating something hot or spicy
There are also further psychological and neurobiological reasons, especially for enjoying sad movies.
Researchers found that watching a tragedy movie caused people to think about their own close relationships, which in turn boosted their life happiness. The result was that what seems like a negative experience – watching a sad story – made people happier by bringing attention to some positive aspects in their own lives.
...watching sad films prompts us to get reflective and feel grateful for the ways our lives and relationships are better than those of the characters on screen
... there might be some serious neurochemical involvement in our happy feelings post-tragedy viewing. According to Paul Zak, Greatist Expert, Professor, and Director of the Center for Neuroeconomics Studies, sad films make us feel empathy for others through the release of oxytocin.