One way is through the use of minor keys. Minor keys have a natural inclination towards a more melancholic and somber mood, which can easily represent the theme of neverending sadness. For example, many classical pieces in minor keys, like Chopin's Nocturnes, can evoke a sense of deep and unending sorrow.
Lyrics play a crucial role too. If the lyrics tell a story of unending grief, loss or disappointment, it can effectively communicate the 'theme of sadness neverending story'. For instance, in some sad ballads, the singer might be lamenting a lost love or a difficult past that they can't seem to move on from, and the melody and musical arrangement support this sense of neverending sadness.
Repetitive melodies can also convey this theme. When a melody repeats over and over, it gives the impression of something that doesn't end, just like a neverending story. The repetition can gradually build up a feeling of sadness in the listener. A good example could be some ambient or drone music where a simple motif is repeated continuously with a slow and solemn tempo.