A helpful article from Mattingly et al. (2023) describes history, business practices, economics, and policy for pharmacy benefit managers (PBMs). Part of this article explains how PBMs make money. They claim there are three primary avenues.

Rebate retention. Plan sponsors pays the list price of the drug net of rebates and discounts received.  PBMs are entitled to some or all of the rebates it negotiates with pharmaceutical manufacturers. On average, “PBMs retain 0.4% of rebates in Medicare Part D and 9% (2012) to 22%(2016) of rebates in the commercial market. [See GAO 2019, Pew 2019]Spread pricing.  Under this mechanism, plan sponsor pays a fixed amount for each drug no matter how much (or little) the PBM pays the pharmacy for dispensing. The difference is the PBM’s gross profit (spread) on that claim.Administrative fee.  Here the plan sponsor pays the cost of prescriptions (net of discounts/rebates) and PBMs only receive an administrative fee.

At first glance, one would suspect
that rebate retention is best for negotiating low prices.  However, rebate retention is actually best at
negotiating large rebates which can be achieved either by good negotiation
lowering net prices or by allowing for high drug prices and large rebates (so
the net price is not much discounted). 
These perverse incentives have made some policymakers favor administrative
fees more.

Incentives for spread pricing are
to squeeze the lowest possible costs from their pharmacy network in terms of
dispensing fees. Administrative fees lead PBMs to do their best to lower their costs
for administering the pharmacy benefit.

See also  The Pharmacy Benefit Managers (PBMs) Unveiled: Your Guide to Understanding Prescription Drug Costs

The mixed incentives even have
lead companies to create multiple versions of the same drug for different PBM
types:

These pricing incentives have led multiple manufacturers, such as Amgen and Viatris, to launch the same drug products at different list prices—a low-price product with no rebate and a higher-price version with rebates—to appeal to different purchasers.”

More more interesting details on PBMs, you can read the whole article here.