The world/utopia as described in Star Trek is a world where there is no poverty and free electricity. You describe Starfleet. Obviously, the series do contain elitism. Joining Starfleet is seen as prestigious. And even on Earth there are slums during the time of the federation. So the “Utopia” is not complete. And Starfleet is necessary to protect the utopia from outside influences.
It is largely based on the premise of having copious amounts basically free energy, free food (through replicators), safety, and a wide open universe for settlers to join when they do not want to stay in the Federation. Basically, it is based on the absence of contention of resources. Until we have that, either through shrinking or expansions of habitat, we will retain conflict.
Thank you Mr. Spockz.