That's a huge question, with an even bigger answer.
I think there's a mixture of things at play, including neurodiversity, the social environment, socioeconomics, cultural capital and early familial relationships.
If somebody has a secure, safe, loving and supportive childhood, one where there is always 'enough' of everything, from food and clothes to affection and joy is expressed in their existence, their abilities, they're supported and encouraged to try in everything, they're in a position where they feel safe and confident in people, not just themselves.
Then put them into education, where they encounter a welcoming, warm and happy school environment. This then helps them to learn to form friendships and play, further increasing the feeling that the world and people is a benevolent place. They're encouraged and supported to grow and maintain friendships of all kinds, creating further positive feelings and relationships intermingle between home, school and where further encouraged in outside activities, there's a strong network of interconnected support and communication. As part of this, they learn in a safe, caring way that maybe there are people whom you don't necessarily become friends with, but that's OK, you can still have pleasant interactions with them (or not, they fade out of view).
As they progress to adulthood, that network of connections changes but there is always sufficient support that they feel safe. So the person is always able to find ways to connect with others - they don't have any reason to feel awkward or confused - and if they encounter any unpleasantness, they're not isolated.
Compare that to a child whose parent actively despises 'clever people' and spends their time knocking the child down, criticising them for the things they are good at and taking pleasure or becoming angry at the things that aren't so effortless for them. Add in children who have been taught by their parents in turn that clever kids are weird, all up themselves and should be brought down a peg or five - or are angry that this kid gets something - and instead of this being stopped and resolved, the able child is told it's all their fault and the reason it happens is because of something wrong with them 'No wonder everybody hates you', 'Why do you keep on showing off about how smart you are? Nobody likes a smart-arse', 'Not so smart are you? You can't even go to school without somebody wanting to hit you'. This then, because of a lack of home and financial/environmental security, is accompanied by insults and criticisms designed to deflate them, based upon such things as not having a nice home, not having the right shoes, their physical appearance, anything that will make them shrink.
As they grow up, they learn that there will always be somebody ready to attack them and it's all their fault, as even their parent hates that about them. Nobody wants to talk about things they like, they are mocked if they open their mouth, mocked if they don't. Maybe there's somebody they do get along with - but even that's up for criticism 'You're playing with that weird kid. Stay away from them, you'll end up just like them'. People are scary. People are mean. People don't like me. And it's all my fault.
If every time you put a hand out it gets slapped hard, you learn to not do it. Soon enough, even if there isn't anybody there that would slap it, you can't bring yourself to take the risk.
Perhaps they're stopped from continuing study because a) the parent doesn't want it, so won't fund applications, won't complete forms, threatens them with being kicked out on the street if they don't get a job at 16/18 or b) b has told them for so long that it's not for the likes of them so they don't believe it's possible.
Maybe somebody then gives the impression that they at least like them some of the time. And before you know it, there's an abusive/coercive/controlling romantic relationship to add to the mix - any signs of getting along with others is treated as cheating, attempting to cheat 'they don't like you, how stupid can you be to think that anybody would ever like you?'.
We can also add in gender based ideology - girls don't like computers, men don't like women that are too smart, ugh - maths, girls don't do maths, you must be a boy if you like Physics/dinosaurs/science fiction, why aren't you interested in makeup and hair like a normal girl, never ever let on to a man that you know more than him, don't think she's suitable for the promotion above James as he wouldn't like that, I'm not sure she would be suitable for that role, she's very, very smart, but I'm not convinced she would be the best candidate in charge of hundreds of thousands of pounds (ie, really smart people are more likely to commit crimes), HOW DARE YOU show me up by talking about Medieval architecture/renaissance music/Ealing comedies/ cars/whatever?
They might continue to feel shame at themselves, they might think 'fuck it, it's part of me and I will not apologise for it', but it still tells them that other people won't like them for something they cannot change.
If you chuck in some ADHD bull in a china shop enthusiasm, some hyperfocus, Autistic special interests that everybody around them make clear are not in any way special to them, some incredibly irritating tapping or stimming that heightens any difficulties around others or just being very easily distracted on top of all that, it's pretty easy to see why one person with high intelligence can find it easy to get along with others whilst another would feel that they don't because of their intelligence; one has a pleasant world where, whilst it still has challenges, their intelligence is part of what makes them 'good', 'nice' or 'likeable', whereas the other is in a precarious place where their intelligence is behind the majority of negative experiences.
Have a tl;dr.
Some people don't struggle because their intelligence isn't a problem for the world around them and they have developed the skills to be able to navigate around other humans and relationships. Some people do because their intelligence is a problem for the world around them.