To me it also seems like hurting oneself "for no reason" unless it's really a lifestyle that makes you happy (staying alone). I
personally cannot imagine not having the people I have in my life, and I'm not even prone to feeling lonely that much, I'm more likely to seek alone time actually. I understand the wish to isolate out of anxiety and/or depression (been there, still kinda there at times), I just find it counterproductive in the end.
No matter what you do in life, you're always at risk of doing it wrong or getting hurt, but then should you stop doing everything? stop living?
Trying will always come with its amount of disappointments and anxiety, but also with the good stuff, the positive feelings and experiences. It seems to me like the best thing is to learn to deal with the disappointments in a healthy way (not saying it's easy at all, but worth it) and to keep trying and growing and getting better at things.