A key notion of economics is that if two people voluntarily agree to something, it must be of some benefit of them at that moment compared to alternatives else they wouldn't have agreed. A market can consist solely of such interaction. A democracy on the other hand involves people via votes controlling what other people can and can't do (in a market context, reducing their control over what, how and to whom they can exchange their labour and products thereof), which necessarily entails some kind of loss (in terms of otherwise-realised unrealised preference) from the people who are not able to do what they'd be doing absent coercion by the democracy's enforcers.
Pure free-market economics adopts the epistemological stance that utility (the economic proxy for value, based roughly on the notion of value being defined as the sum of people's realised preferences) isn't quantifiable, so no potential utility gained from the results of the democratic thwarting of some people's preferences can outweigh the definite loss from those people not realising their preferences.
Other schools of economics do view utility as quantifiable, so it's possible to say that there can be a net benefit from interfering with someone's preferences based on the result of democratic process. They disagree however in how utility is best quantified.
Schools of thought external to economics often have measures of value that differ substantially from the economic notion of utility. In particular, any scheme that assumes the existence of moral absolutes is fundamentally incompatible with the notion of utility.
It's hence important to consider that any economics that makes recommendations (that isn't just econometrics/prediction) is necessarily based on some particular philosophical propositions regarding what's valuable. Without this, economic discussion tends to degrade to people talking past each other because they have fundamentally different theories of value, fundamentally different metrics for the "optimal" in social optimality.
To put it another way, whether or not there is an optimal solution depends on how optimality is defined, so discussing solutions without defining optimality is pointless.