Enter insurance companies. They don't want to pay $1,000 for a $50 drug so they negotiate. But there's too many insurance companies for them to have good leverage and efficiencies in negotiation.
Enter Pharmacy Benefits Managers. They get hired by insurance companies to negotiate with drug companies and pharmacies. Thus the buying power is pooled and they only have to pay people to negotiate one time.
GoodRX is like the last category. Except that instead of getting paid by insurance companies they sell user data and collect some fees from pharmacies and drug manufacturers.