When brand name drugs release under patent, the manufacturer chooses their own price.
Often times, the price is set significantly higher than the cost of production in order to recover from development costs (usually hundreds of millions of dollars); including research and testing for safety and effectiveness.
Once a patent expires, other manufacturers can begin producing generic equivalents. These manufacturers are able to charge a reduced price because they haven’t incurred the development costs in order to establish the drug.
With generic drug manufacturers entering the market, it’s strongly encouraged for them to price competitively in order to turn a profit from production.