For those who might not be aware of it... Gene Roddenberry attended several seminars made by Jacque Fresco on Cybernation (as it was called back then).
Today, it's been renamed into 'The Venus Project'... and the core of this project is called Resource Based Economy.
Essentially, it describes a transition into a moneyless society where currency, trade and any form of servitude do not exist.
And before you dismiss it as a fantasy, bear in mind that RBE is based on technological automation - namely robots, machines and algorithms do all the dirty work, while Humans are liberated to pursue higher things.
All Humans would also be exposed to relevant general education, critical thinking and problem solving.
The notions of property, governments, etc. no longer exist.
Why?
Well, when you live in a society that produces things on demand or has things ACCESSIBLE on demand, you have no need of ownership.
Our technology (in real world) surpassed this level around 40 years ago.
It would take too long to go into all the intricate details, but suffice to say that Roddenberry based his idea of a moneyless Federation on Resource Based Economy.
Namely, you do not require infinite resources to have a post scarcity society.
Look at it like this, Humanity today is producing enough crops to feed over 10 billion annually, and yet, a lot of this produce (over 40%) is discarded based solely on the fact that it's aesthetically unpleasing (otherwise there's nothing wrong with the food itself - its still nutritious/edible).
Then, a lot of it goes to feed the animals (which is unnecessary because Human biology doesn't require animal protein to live or thrive - there's sufficient peer-review studies confirming this btw) and its effects on climate thanks to animal agriculture at large (producing enormous quantities of Methane that's even worse than CO2, and Methane emissions encompass a good chunk of climate change numbers).
At any rate, what you need to achieve post scarcity is abundance (or more than enough).
And that we had the ability to do for decades.
There is an enormous quantity of geothermal energy that can be harvested via 2 ways... volcanoes, and drilling deep in to the Earth (could have been done since the 1950-ies because we've been producing synthetic diamonds since then).
We also don't have issue with housing... there's more than enough to go around.
In the USA alone, there's enough empty homes to house each homeless person about 6 times over.
In the EU, there's enough housing to house each homeless individual 3 times over.
China built hundreds of new and empty cities in a span of mere 15 years.
We also have 3d printers that can build houses in about 24 hours, or half as much time.
Why did the Humans in Trek universe decide to go this route?
Probably several factors:
1. WW3 - just look at what wars are doing to us in real life.
2. First Contact with the Vulcans.
I would surmise that Humanity decided it was time to clean up its act... and actually, it took them 50 years to eradicate war, poverty and diseases (per 2 statements coming from Deanna troi - once during TNG series and second time during First Contact movie - it was in the movie she actually stated the time frame).
Now, bear in mind that while the Federation does bear resemblence somewhat to RBE, it's not a fully realized RBE because it still has people in positions of power, leaders, prisons/'police', etc.
I would imagine that various vestiges of what exists in the current socio-economic system were retained for TNG because Roddenberry either didn't grasp the full concept of RBE and how it might work, or the writers simply wanted to keep things somewhat relateable - plus, Trek was a show made for American TV... showcased in a very much so Capitalist culture.
Plus, Trek had a lot of writers, many of which projected their ideas onto the Federation from current day (even though such things would simply not happen in such a society once you take into account epigenetics and neuroscience in play - but then again, many writers also didn't know about those things, and by rewatching a lot of TNG, I can see their ignorance showing - the information existed back then, though admittedly, it was probably harder to access due to lack of Internet at the time).
At any rate, the Federation in TNG represented a possible future where science and technology are used for the well-being of EVERYONE as well as protecting/preserving the planet, and where EVERYONE are exposed to relevant general education (becoming generalists), critical thinking (ability to question the information given to them, themselves, their own culture, background, etc.) and problem solving - such individuals would technically have 0 need for leaders or politics, and indeed as is dreadfully apparent from real life, politicians are NOT problem solvers (they are mainly trained in politics, not in the things Humanity and the planet need for survival, prosperity or sustainability).
Many people would argue that we do not have necessary knowledge or resources to solve our problems... but neither were a problem for a good portion of 100 years now - I can elaborate further and provide evidence for those who might be interested (from credible sources).
But bear in mind I'm using real life examples to showcase how the Federation could have accomplished what it did.
In actuality, what we saw in the 24th century Federation should have happened at least in the 23rd... by the 24th, it should have been far more hyper advanced, because scientific and technical progress occur at faster than exponential rates the more automation is being integrated and society becomes more technological and scientific as a result.
Most people think in a linear fashion, and this is one of the reasons why it is a problem for them to think that we could easily transition into a moneyless society ourselves - they are stuck in the current mindset because it is the culture in which they grew up in and currently live in.