I'm not proposing a solution to all conflict. There would still be tensions between countries just like there are today, and some of them will try to do bad things like they already do. Children would also be under the authority of their parents/guardians just like they already are, which leads to problems if the parents/guardians are bad. I can't control how countries or parents will behave, I can only offer suggestions on how those situations might be handled. It is of course subjective whether a government has lost its legitimacy by harming other countries, harming its own people, or enabling evil within its borders. Country A may see country B as evil and illegitimate because it aborts babies and decide to wage war. Other countries might see this as unjustified aggression and help defend B. But this isn't really any different to what happens already. Only currently the wars are waged by unaccountable governments who often have very different views from the population and the wars aren't usually about ideology but power. Wars for power should be less frequent if an individual right to secession is widely accepted because any people or lands that are captured must have a right to break away or the government will look illegitimate.
I'm not saying the system I propose will lead to the best outcome. I'm saying it's more just and I think it will lead to better outcomes than current systems. But the emphasis is on being more just. Trying to get the best outcome is impossible because people don't agree on what that is, and the utilitarian pursuit of better outcomes could enable all kinds of atrocities as an alleged means to that end. Giving people more freedom can lead to bad outcomes because they might use that freedom to self-harm, but it's far more just than restricting everyone's freedom and in any case it probably will lead to better outcomes too because the power to restrict freedoms tends to be abused.
what if not everyone consented to be in that system?
I'm saying people can form any kind of society they want. It can be communist, fascist, open borders, closed borders, just don't expect to be treated nicely by neighboring countries if you're harming them or they think you're doing heinous things within your own borders. And I think not allowing people to leave your country should be seen as a heinous restriction on freedom. Is it possible that some people will want a system of government that doesn't let people leave? I suppose a retarded or malevolent majority could want that, but the minority who don't want that should be allowed to leave and the fact that they aren't would make the government illegitimate to my mind.