How does it do this? Through the Medicaid Drug Rebate Program. Medicaid.gov explains:
The Medicaid Drug Rebate Program is a partnership between CMS, State Medicaid Agencies, and participating drug manufacturers that helps to offset the Federal and State costs of most outpatient prescription drugs dispensed to Medicaid patients. Approximately 600 drug manufacturers currently participate in this program. All fifty States and the District of Columbia cover prescription drugs under the Medicaid Drug Rebate Program, which is authorized by Section 1927 of the Social Security Act.
The program requires a drug manufacturer to enter into, and have in effect, a national rebate agreement with the Secretary of the Department of Health and Human Services (HHS) in exchange for State Medicaid coverage of most of the manufacturer’s drugs. Manufacturers are then responsible for paying a rebate on those drugs each time that they are dispensed to Medicaid patients. These rebates are paid by drug manufacturers on a quarterly basis and are shared between the States and the Federal government to offset the overall cost of prescription drugs under the Medicaid Program.
In addition to signing a national rebate agreement, drug manufacturers are required to enter into agreements with two other Federal programs in order to have their drugs covered under Medicaid: a pricing agreement for the Section 340B Drug Pricing Program, administered by the Health Resources and Services Administration, and a master agreement with the Secretary of Veterans Affairs for the Federal Supply Schedule.
Please note that manufacturers participating in the Medicare Part B program must first obtain a national rebate agreement.
These rebates are fairly large. For non-innovator drugs, the rebate is 13 percent. For other drug categories (e.g., innovative drugs, blood clotting factors, and drugs approved exclusively for pediatric indications) the rebates can reach up to 23.1 percent.