Tax has to be used to counter the harmful externalities created by the market,
The internal that externalities are external to is the market. It is because they are external to market pries , to the calculations people make about their actions, that they are externalities.
It is not that they are created by the market. Take CO2 emissions, something we all agree is an externality. In a planned (say, Soviet) economy they are still external to the decision making process. They’re externalities. In a market system with a carbon tax they are no longer. In a Soviet system that includes the costs of emissions they are no longer an externality.
They’re not caused by markets, they are external to them.