I'll start with describing "an advanced society". Imagine a society in which the cost to build and maintain a robot is less than the cost to grow and feed a human.
Growing and feeding a human requires food, and food requires energy. Land growing crops has a cost; if that same land (or same crops) converted into energy is sufficient to makes and maintains a robot that is more capable than a human at a given task, that human isn't efficient at that task (in the medium term; in the short term, you could have excess humans).
In a sufficiently advanced society, robots and AI are more efficient than humans at every task. This would include everything from mining to developing new technology.
Such robots/AI do not have to be sentient. It might just turn out that describing a problem domain from natural language isn't "AI hard", and solving that problem domain through experimentation isn't that hard either. So you literally say "I want a better hand computer", and the non-sentient AI looks at human behavior, works out what you mean, and solves that problem.
In this society, a given human has no natural economic need for another human; there is nothing the other human can sell them that they couldn't get cheaper from an AI.
As you transition to such a society, wealth is going to be held by various humans. They are quickly going to pass on the management of their wealth to AIs (as, again, AIs do a better job), harvesting a small amount of it to enjoy themselves (if they harvest too much, their wealth will erode).
Those without wealth will find themselves without economic purpose. Initially governments will support said economically worthless people with stuff like basic income. Almost all services, from police to military to legislation, ends up being taken over by AI and robots; areas where this doesn't happen will experience a constant drain on their relative competitiveness compared to areas that do. Vanity jobs, like "President" or "Sherriff" can exist, but they (economically) are little different than providing humans with toys to amuse themselves. Sometimes the toys can shoot out someone's eye, but they aren't important.
It has been said that power flows from the barrel of a gun; but really, it flows from economic usefulness. The greatest power the populace has ever had is the power to die and deprive the ruling class of their productive surplus. In modern times, the non-ruling class's productivity in first world nations is immense, and huge amounts of wealth are harvested by providing the non-ruling class with economic and political distractions, like democracy, human rights, salaries and home ownership.
With the collapse of the economic usefulness of humanity, and a ruling class still existing, the non-ruling class becomes useless to the ruling class. Democracy and the like will be dismantled over time, and things like universal basic income and human rights will fade.
As this happens, enslaving otherwise useless humans could become something a "soft-hearted" rulership caste could do. Rather than let those purposeless drones starve, they are given economically useless "jobs" that amuse the ruling caste member.
So long as this all falls within the "harvested excess" play money of the ruling caste member, where the vast majority of their wealth goes towards shoring up their power, this is economically feasible.
Now, over time, the rulership caste themselves is worthless. A self-perpetuating non-self aware AI+robot engine that seeks to maximize its own power would be more efficient than one with a parasite ruler attached to it, simply due to the drain of resources and possible executive power errors of said ruler. So this phase, where a cruel sociopathic rulership caste enslaves the remnants of humanity for amusement, would only be a passing one.