I don’t believe there are people who are useless to society. Even the most mentally-insane people can be used to advance scientific research in psychology, sociology, criminology and so forth. When it comes for prisoners in maximum-security for life, their stories can serve well in documentaries.
Even those who are unable to work are not necessarily useless, as they can be of purpose some other way, like making their families happy, which is also a respected purpose when you’re unable to work due to an extreme disability.
Purpose does not always have to come from employment, and purpose doesn’t always have to be directed to other people than yourself, as you are also under the definition of “people”.
I just watched yesterday the classic movie “Rain Man”, one of the most known movies about autistic people in times where autism was not very well known. In the movie, the main character’s autistic brother, which was mostly a burden for him for a large portion of the movie and was unable to work and lived in a special institution, was actually proved to be very competent in gambling, and thus has helped his brother return his large debt, to the point the casino they were gambling in expelled them because the casino was losing money because of the autist’s genius.
My grandmother in her final years believed to be meaningless, one of the reasons being she felt very lonely (even though I visited her regularly) and was in pension. However, she was a great artist with phenomenal talent and to this day I have many paintings, made by her, in my apartment. The main reason we did not sell her paintings was because she wasn’t - and isn’t - a well known artist, and unfortunately your name as an artist is also important when selling your creations.
So, what we can conclude from all of this is, that no matter who you are, as long as you’re human, you have at least some degree of potential you can use (or others can make use of, not necessarily in a bad way) in the name of self-actualization and of productivity. Where there are humans, there is potential for productivity and for creation.
Let us, therefore, not fall victim to the delusion that we are meaningless, because as long as we are alive, we have the chance to be helpful and/or productive to a degree. In addition, few are the people in the world, theoretically that don't matter to anyone whatsoever.