That was the prescription to deal with one man. And you left out part of the quote. The most important part. Their prior discussion was about how to get to heaven. And you have to be perfect to get there. But you cannot be. It's not possible. The only way to get there, is through faith in the One who IS perfect.
Jesus told the young rich man, you'd have to keep all the commandments. And the you man said I have kept them all. Jesus knew that wasn't true. So Jesus starts listing them. And the young man said, "all of them I have kept. What do I still lack?" Then comes the full quote:
Jesus answered, “If you want to be perfect, go sell your possessions and give to the poor, Then come, follow me.”
This man's heart was that his possessions were more important to him. And he hadn't been listening to the teachings of Christ. Which were, believe in who I AM. What does he say at the end. It's harder for a rich man to enter the kingdom of heaven, than for a camel to go through the eye of a needle. And the disciples asked, "who then can be saved?"
Then comes the crux. The set up in the quote is that you cannot earn your way to heaven. As Christ tells them. "With man, this is impossible. But with God, (Him) all things are possible."
If you think that the only way for a rich man to enter heaven is to sell all he has, then you missed the point.
The same thing about Jesus being a socialist. We are to be generous. And we are to give priority to the poor. And we are to pay even unfair taxes. But doing all or few of these things is not how anyone gets to heaven. And he says that, repeatedly.
When one of the rich pharisees comes to him at night (apparently to avoid being seen by his fellow pharisees), Jesus doesn't tell him to sell all he had to follow Him. He tells him that he must be born again. And explains how. And then why too many won't. The core of the gospel: John 3:16.