There are many reasons behind mergers and acquisitions. Some are based on strategic business needs and some purely financial.
Some of the main reasons for mergers and acquisitions:
Vertical integration: Imagine you are a manufacturer and depend on company X for a unique and crucial part. You might acquire X to secure your supply chain. Or a mining company might buy a company that owns ore deposits.
Horizontal integration can be done to achieve economies of scale (i.e. when several car companies merge and develop cars on shared platforms), increase market share, or create complementary offerings (e.g. a clothing company buying an accessory company)
Sometimes companies with excess cash by other companies to increase their return on investment of the cash.