My heart goes out to you. And to him. At 17, my son was like this and we were both seriously worried and unhappy about it. You should see him now, aged 21 - he has several groups of friends, has had several girlfriends since meeting his first one, 15 months ago. He has done a LOT of work on himself. He is neurodivergent and just didn't get on at school. Having no friends at school deeply dented his self-esteem.
I would be direct with him but very gentle. Say you see that he is struggling to connect with the world beyond the safety of home, that it's clear he has the qualities he needs (as proved by work and adult friends of yours) but maybe not the confidence to use them to get the most from his life. Say to him that it may be a bit tough but the sooner he learns the necessary skills, the easier the rest of his life will be.
SKILL 1: Genuinely learn to like and accept yourself. Feel confident in your own skin. Don't seek approval for your existence from others and their reactions to you. Do this actively. Choose two ways to take care of your body that get you out of the house - maybe weightlifting and swimming or cycling or running. Maybe join a cycling club or running club or bootcamp. Gradually the people you meet become familiar and friendships might emerge. And find one hobby. DS chose music. He now realises he missed loads of overtures of friendship in his teens from fellow musicians, due to his neurodivergence but he did become a really good musician and now plays in a band. Whatever your son loves - however geeky - get him out into the world with fellow enthusiasts. Online mates are fine. But encourage online friendships to materialise - meet ups at expos, gigs, talks etc. DS met people online in his teens who he eventually met in real life and they are now his closest mates due to shared interests.
SKILL 2: Care less about what others think of you and more about what you think of them. If people are unkind, judge them! Don't try to ingratiate bullies or fickle friends. Coolly assess whether you value and respect such people and respond to them accordingly.
SKILL 3: Embrace all kinds of friendship - especially very casual ones. Neurodivergent people often prize deep connection very highly whereas NT people are happy to hang out and get wary of the intensity of ND people. If he gets on with the LGBT crowd, he could check in with them and see what they are up to after college or at the weekend some time. He doesn't have to be bi to have LGBT friends.
It's also fine to join a hobby club and just see people there and for nothing else to come of it ever. Not to put pressur eon himself to get great friendships from it.That gentle sociability is a form of valuable connection. Bit by bit, these connections slowly grow. (DS had NO friends. He was dangerously lonely. He volunteered at a charity and was befriended by fellow volunteers he felt he had 'nothing in common with'. Four years later, they holiday together, they cross UK to catch up with each other at the weekends. They are still very different from him in their interests but what they have in common is that they are good kind people who like each other and he now hugely values that.
DS learned to embrace all kinds of friendships in his quest to find any friends at all. One of his close acquaintances is a man in his seventies who shares a passion with DS. They meet up for coffee once a month or so, have done some work together and he has been great at helping DS network in his chosen profession.
To help DS gain these skills, we found CBT techniques and worksheets hugely valuable. If there is an adolescent CBT group locally, it might be worth him joining it. DS was extremely resistant to CBT for a long time and said it had no value whatsoever. it did. We saw the changes before he did. He stuck at it in a kind of desperation but now sees that it changed his attitude to life and made him an outgoing, confident and much happier person.
Sorry for long post but we struggled so much and it was such a painful time, so I really worked on it with him and this was the key stuff that emerged as valuable out of a whole load of trials and errors. DS still has a lot of problems from being ND, but loneliness is no longer one of them and it used to be the biggest block in his life. It can be overcome. If he can do it, truly, anyone can.