It sounds to me like you have developed a phobia. Phobias usually have a basis in an event that the person found overwhelming. In order to deal with it, the person then compartmentalizes the anxiety and fear to a particular kind of person or event. It’s like people who get afraid of all dogs because one dog bit them.
In your case, being rejected was more than you could bear. So you unconsciously decided to block the feelings (and the people) associated with rejection instead of deal with them. As you have discovered, it’s not that easy. A person who is afraid of dogs can stay away from most dogs most of the time. But social media and life in our community makes it nearly impossible to avoid seeing other people who are in successful relationships.
Please see a counselor. You can’t handle this on your own. The good news is that treatment of such issues is usually successful. You need to face the rejection you’ve been avoiding and learn to move on in your life. You deserve to get past this and to make yourself open to loving and being loved.
I wish you well.