Is comparative advantage undermined by a welfare state? When liberalising trade with developing economies like China, states like the UK seek to benefit from the comparative advantage of cheaper imports.

Cheap imports undercut some native industries (eg. steel making, ship building, pottery) causing (at least in the short term) joblessness and associated negative social outcomes.

The thinking (IIUC) is that those displaced from the marketplace by the imports should move to higher-value-add industries, but in many cases this does not happen. For example towns like Stoke on Trent in the UK whose native industry was decimated (at least in part) by overseas competition, are characterised by chronic joblessness and associated social problems.

In a welfare state like the UK, the cost of those social problems are then borne by the state.

To what extent does this undermine the comparative advantage seen by the UK from cheap imports?
The basic result about the effect of trade on income distribution is Stolper-Samuelson in the Heckscher-Ohlin model, which says that trade liberalization is associated with a rise in the prices of the factors of production that are used intensively in the production of goods the country has a comparative advantage in, and vice versa. If you take "skilled" and "unskilled" labor to be two different factors of production, for instance, Stolper-Samuelson says that a country with abundant skilled labor lifting trade barriers should lead to an increase in income inequality. A welfare state committed to keeping relative incomes of workers within a certain range may need to raise distortionary taxes to expand various income transfer programs to "unskilled" workers in this case, which could lead to inefficiency for various reasons. (Even if the taxes used to finance the income transfer are lump-sum, as long as the benefits phase out this leads to high effective marginal tax rates on the lower end of the income scale, i.e a disincentive to work and to acquire new skills.) In this sense, it's indeed true that a generous welfare state can reduce the efficiency gains from free trade. 

The rest of the answer is a rant about the concept of "strategic market dumping" that was brought up in the comments, so if you're not interested you can skip that part.

Things like "strategic market dumping" are ill-defined concepts that are usually used to justify tariff increases without having much backing in theory. If "dumping" is expected to go on for a finite period of time and the associated good can be stored at no cost, for instance, then in a perfect foresight world there's an arbitrage bound on the price of the good today which forces it to grow at a rate less than or equal to the real interest rate available in the broader economy. Adding storage costs does not change the basic result very much. In that case, "dumping" is not a good strategy to begin with - if you try to do this, people will buy up the goods you're selling at low prices, hold them until you reverse your policy, and then flood the market with goods they have stored up in their inventories once you stop the "dumping", leaving you worse off. To justify a policy of industry protection, you have to argue that the government can see the reversal of the dumping policy coming and private agents can't - in this case, the real return on an investment in producing and storing oil would be higher than the market real interest rate is saying it will be, so the market outcome will be suboptimal. It's easy to justify any government intervention by saying that the government is clairvoyant and private agents are not, however.

What about labor market (or, more generally, factor market) frictions? Isn't the point of "dumping" to eliminate your competitors through "artificially low" prices which force them to go out of business? Well, here you're making the mistake of assuming that the government knows about labor market frictions and the private sector doesn't, therefore the government should do something about the situation. In real life, the private sector is well aware of the search frictions in the labor market, the difficulty of firing workers in some countries, etc. This means that if they expect the "dumping" strategy to be reversed in the future, they will choose to borrow money or raise capital to stay in business. They will downsize in response to the "dumping" policy, but not as much as you think they would, and certainly not as much to make a government "protection" of the industry a good policy.

Does this mean markets can never allocate resources poorly? Of course not - if the country doing the dumping manages to fool private agents into thinking their "dumping" policy was permanent while it was temporary, then the market allocation will be suboptimal. However, in hindsight every price and every allocation is wrong. We certainly don't expect market allocations to be optimal ex post, so it's not surprising to see cases where it seems like the market allocation was poor and led to many workers being stuck in jobs where wages fell due to international price changes of goods. In fact, this would happen in a stochastic world where markets were functioning perfectly and giving you an ex ante Pareto optimal allocation of resources. Even a social planner with access to all information available at a given date and the mental capacity to solve the associated economic calculation problem would act in ways that sometimes seem foolish ex post. This doesn't mean the social planner is not doing his job properly, it just means there are things about the future that even a social planner can't know with perfection. The argument is no different for market allocations - allocations that are poor ex post do not justify government intervention ex ante.