Simple financial theory shows that the total value of a company should not change if its capital structure does. This is known as capital structure irrelevance, or Modigliani-Miller (MM) theory. Total value is the value of all its sources of funding, this is similar to a simple (debt + equity) enterprise value.
The MM argument is simple, the total cash flows a company makes for all investors (debt holders and shareholders) are the same regardless of capital structure. Changing the capital structure does not change the total cash flows. Therefore the total value of the assets that give ownership of these cash flows should not change. The cash flows will be divided up differently so the total value of each class of security (e.g. shares and bonds) will change, but not the total of both added together.
Looking at this another way, if you wanted to buy a company free of its debt, you would have to buy the equity and buy, or pay off, the debt. Regardless of the capital structure you would end up owning the same streams of cash flows. Therefore the cost of acquiring the company free of debt should be the same regardless of capital structure.
Furthermore, it is possible for investors to mimic the effect of the company having a different capital structure. For example, if an investor would prefer a company to be more highly geared this can be simulated by buying shares and borrowing against them. An who investor would prefer the company to be less highly geared can simulate this by buying a combination of its debt and equity.
MM theory depends on simplifying assumptions such as ignoring the effects of taxes. However, it does provide a starting point that helps understand what is, and is not, relevant to why capital structure does seem to matter to an extent. The different tax treatments of debt and equity are part of the answer, as are agency problems (conflicts of interest between shareholders, debt holders and management).
There are extensions to MM theory which suggest that the actions of market forces, together with the tax treatment of debt and equity income in the hands of investors, means that for most companies the gains that can be made by adjusting capital structure will be fairly small.
Given that companies would not deliberately adopt inefficient capital structures, we can assume that all companies have roughly equivalently good capital structures — so from a valuation point of view we can reasonably assume that capital structure is irrelevant.
Capital structure irrelevance is closely related to dividend irrelevance.