The UN is the main realisation of the "international community". Being a country means being recognised as such by other countries. This is done through the UN.
What a country gains by being in the UN is a platform from which to negotiate with other countries. Being in the UN means that your country is recognised by the international community. It means that your government gains legitimacy from this recognition. And if someone tries to invade your country, or depose your government, you have a forum to seek support.
If you withdraw from the UN, you would not have the same platform to make your point to the rest of the world. Their is a requirement in the UN to maintain peace. But if you withdraw this wouldn't mean that you could then declare an aggressive war with impunity. But you would not be in a position to defend your actions.
Withdrawing from the UN would leave a country a pariah state, that nobody wants to do business with, because it is a country that is acting outside the norms and rules of international cooperation.
So we have seen, even after countries like Iraq were strongly condemned by the security council (after the '90 invasion of Kuwait), and had a UN backed army attacking their country, they did not leave, because they valued the platform that the UN gave.
So this leaves the interesting case of Switzerland, which didn't join the UN until 2002. The Swiss are something of a special case. They were already a well-recognised country. They had not been involved in the two world wars. They chose not to accept the platform that being a member of the UN gives. In other words, they deliberately chose less influence, to preserve their policy of neutrality. They were not treated as a pariah state, as they had a long tradition of non-aggression towards other states. They were "trusted".
The obligations placed on countries don't amount to much. And the benefit of being recognised far outweighs them.
The UN was not intended to be "fair". It is not intended to treat all states equally. It is intended to provide a means of avoiding war. The victors of World War 2 are given a special status. Without this special status, the USA and Russia would never have participated. And without the USA and Russia there would have been little point in the UN.