To aid henning's answer; there are some models that delve into this. Basically various groups within the same country are competing against each other by means of imposing external duties (tariffs of quotas). It's known as the "protection for sale" model. To quote from a review paper on this.
Over the past decades, the Grossman and Helpman (1994) model of “Protection for Sale” (PFS) has become the most influential
one in the political economy of trade. The PFS model provides a clear-cut prediction on the relationships between the level of
protection and the import penetration ratio: protection is positively related to the import penetration for politically unorganized
industries, but negatively related for politically organized ones. This simple relationship is based on an equilibrium model where
each politically organized industry proposes campaign contribution bid function that specifies the relationship between campaign
contributions and tariffs. Then the government, given these bids from industries, chooses tariffs so as to maximize its objective
function, which is a weighted sum of campaign contributions and social welfare.
Several theoretical concerns, however, have been raised about the model. First is the question of whether the model itself is a
reasonable depiction of reality. Should lobbies be thought of as “buying protection” in a menu auction as posited by the model? Or
is it that contributions buy something else, like access to politicians? Ansolobehere, de Figueriedo, and Snyder (2003), for example,
argue forcefully against thinking of contributions as buying policy. [...]
[And a couple of more technical points which I'll omit here.]
Despite these concerns, the PFS model has had much empirical support. A number of studies have estimated the protection
equation derived by the model and found that the parameter estimates follow the pattern predicted by the model (e.g., Goldberg &
Maggi, 1999; Gawande & Bandyopadhyay, 2000; Mitra, Thomakos, & Ulubasoglu, 2002; Eicher & Osang, 2002; McCalman, 2004).
Recently, researchers have extended the original PFS model by incorporating firm size (Bombardini, 2004), foreign and domestic
lobbies (Gawande & Krishna, 2004), lobbying of both upstream and down stream producers (Gawande & Krishna, 2005), and labor
unions and labor immobility (Matschke & Sherlund, 2006). While the original model accounts for tariffs, its quota version was also
constructed and estimated (Facchini, Van Biesbroeck, & Willman, 2006). These extensions, in effect, graft some complications onto
the original PFS model and provide evidence that additional factors are also essential. It should be stressed that as the extensions
typically leave its basic predictions unchanged, they seem to provide more evidence in favor of the original PFS framework.
So it might not be a complete model, but it has a fair amount of empirical support. The reason why customs duties seems to be "haphazardly" applied by governments, i.e. to some things but not others is basically explained by this PFS model to a fair extent.
As henning mentioned free riding... that's also an issue, but not in the most obvious fashion, but rather within groups:
Olson hypothesized that a latent group's ability to organize and contribute toward providing a public good might be jeopardized by free riding. The politics of trade protection feature the collective action problem, since protection benefits all firms in the industry including those who contributed nothing to attaining it. This paper examines the extent of free riding in lobbying over tariffs in the context of the Grossman and Helpman (1994) protection-for-sale model in which industry lobbies seek to bend government policy in their favor. Previous investigations of the model have produced the puzzling result that governments are largely welfare-maximizing and care little about campaign contributions, in contrast to numerous examples of welfare-reducing policies that have in fact been bought cheaply by special interests. We think the result arises because the model assumes away free riding by firms which hinders industry's ability to organize politically. We introduce free riding into the Grossman–Helpman model, allowing industries to be partially organized. Using a new data set on US trade barriers, we test the model using estimation methods new to this literature. The estimates support the model's predictions and reveal that the extent of free riding by manufacturing firms can help resolve the puzzling result. [...]
A key assumption behind the Grossman–Helpman prediction [...] is that industries failing to achieve cooperation in lobbying offer no contributions to the policymaker, ruling out the possibility that individual owners of sector-specific capital may have a strong private incentive to lobby the government. GH implicitly assumed that the fixed costs of lobbying were greater than the net gain to any individual offering of a private contribution schedule to the policymaker. In the data sets used by Goldberg and Maggi (1999) and Gawande and Bandyopadhyay (2000), however, every four-digit Standard Industrial Classification (SIC) industry has some positive contributions. It thus seems unrealistic to assume that some industries are unorganized and offer no contributions. In practice, capital owners are organized into firms that lobby the government through political action committees. It is likely that corporations, particularly large ones, have incentives to lobby the government over trade policy even if the industry as a whole is unable to overcome the free rider problem and organize a cooperative lobby.
Our solution to this problem is to distinguish between cooperative lobbying, in which the industry lobby acts to maximize total industry profits, and noncooperative lobbying, in which each firm acts to maximize its own profits. [...]
[Intra-group] free riding explains why we might observe a low level of trade barriers even when it is cheap to lobby the government.
More recent papers (2016) have added the separation of power as a feature to the [PFS] model. Basically, the
government is no longer treated as a whole, but rather the executive is seen as taking a gamble in
free-trade agreement negotiations by hoping that there won't be enough of a blocking minority (fueled
by lobbying) in the legislature, which then needs to ratify the agreement.
I for one still find these models rather lackluster in view of the direct lessons that protection
[from free trade] can be "bought" straight at the ballot box by some groups. In a context where there already exists political polarization for other reasons, relatively small groups can act as arbiters at the ballot box (in "battleground states" and similar constituency organization that makes the votes of most others less relevant/powerful) and achieve their group goals. Alas I could not find much in the way of political economy models that have tried to incorporate such post-2016 lessons...