There is not enough time or space to lay this all out for you. It basically comes down to this:
They make the prices (for cash customers) or sign contracts for reimbursement (for insurance customers) that allow them to make a high enough profit to stay in business.
I learned along time ago,
Profit is your most important product.
If you fail to make a sufficient profit, you will not be able to provide the services to your patients you want provide. You went to school to help people and if you or your pharmacy or pharmacy department does not make enough money to cover your costs, you get to help nobody.....