Free trade is, on the whole, one of the few otherwise controversial policy topics on which economists have near-perfect consensus. Historically, this consensus has long been strong in the English tradition (Hume, Smith, Ricardo, Mill), albeit less strong elsewhere. Famously, 1028 American economists signed an unsuccessful petition in 1930 begging Herbert Hoover not to approve the Smoot-Hawley tariff. If the IGM Economic Experts panel is any guide, consensus remains firm today.
That said, off the top of my head, various cases in which some modern economists have departed from advising free trade include:
- Import substitution and related protectionist development philosophies in the early postwar era. These were never (as far as I know) advocated by many economists in the neoclassical tradition, but they certainly had support among influential other figures, notably Raúl Prebisch; enough that they were put into action in many parts of the developing world, especially Latin America. The mainstream verdict on import substitution is that it was a costly failure, although there are notable heterodox dissenters like Ha-Joon Chang. Dani Rodrik also has a slightly less heterodox record of free trade skepticism.
- Cases of market power. Here, economists do not necessarily advocate departing from free trade in practice; but they do recognize that (in principle) it can be individually optimal for countries with either some monopoly or monopsony power to try to manipulate the terms of trade in their favor via trade restrictions (potentially either import or export tariffs). Many large, developed countries probably have some market power of this kind, and specialized commodity suppliers do as well. This observation is the basis of some economic theories of trade agreements, which are modeled as devices for countries to coordinate on a Pareto optimal free trade regime and overcome their individual desire to manipulate the terms of trade.
- Aggregate demand management when monetary tools are limited (due to the zero lower bound). Paul Krugman has discussed how protectionist clauses in stimulus plans could in principle be globally optimal, by allowing countries to retain more of the benefits of their own stimulus and thereby encouraging them to do more. Another case is where countries facing the zero lower bound could impose tariffs on unconstrained countries, in an attempt to redirect expenditure to demand-constrained economies. That said, Krugman still (mostly) favors free trade and doubts that the benefits of such a policy would overcome the cost to the global free trade regime.
Distributional consequences. This is a common refrain in popular critiques of free trade: many pundits argue that even if trade is beneficial in some aggregate sense, its adverse distributional impact (e.g. hurting the already-suffering manufacturing workforce) negates the overall benefit. Indeed, in models where gains from trade arise from differing factor endowments, the whole point is that some factor (the domestically scarce but internationally not-so-scarce one) will lose; this is the idea behind the Stolper-Samuelson theorem.
Traditionally, most economists have argued that it is better to have free trade and address any distributional or insurance objectives through the overall tax-and-transfer system. Whether not this conclusion holds in a formal model, however, depends on exactly what instruments are available to the government; it's conceivable that trade barriers would be an optimal second or third-best policy in some cases. The left-wing heterodox economist Dean Baker has strenuously argued along these lines (though he has certainly not offered a formal model). More in the mainstream, an early version of Autor, Dorn, Hanson (AER 2013) made a suggestive stab in this direction with a back-of-the-envelope calculation showing that the deadweight loss from transfers induced by Chinese trade was a substantial fraction of the theoretical gains from trade - though this calculation was rough and evidently removed from the published version. Notably, Autor was one of the few IGM panelists with an "uncertain" reply about the benefits from trade.