Why is it possible to tell that, in the case markets are competitive, capital earns its marginal product? What's the formal explanation and what is the economic intuition behind it?
Let's do the maths in a simple way:
Take profit function: $B = p · f(L,K) - w·L - r·K$
Where $B$ is profit, $L$ is labour and $K$ means capital. $f(L,K)$ is the product function, $p$ is price and $r$ is the rental price of capital and $w$ is wage.
Take $PMg(K)$ as marginal product of $K$ and know that $df(K,L)/dK = PMg(K)$
In order to optimize $B$ with $K$ take the first order derivative:
$dB/dK = p · PMg(K) - r = 0$, therefore:
$PMg(K) = r/p$, so the real gains of capital $r/p$ equal to its marginal product $PMg(K)$. This is an equilibrium for capital under perfect competence, if marginal product is greater that its revenue, product would grow that would make marginal product lower (due to the law of diminishing returns).
This is a simplification, I'm not taking in account labour and supposing that capital has a marginal product. Notice that if we not suppose perfect competence, price would be a function of product so we would have different maths.
If you take into account labour and capital which separate marginal products, you have to take the Lagrange optimization and reach:
$PMg(K)/r = PMg(L)/w$
Try to minimize cost fixed to product or maximize product fixed to cost and you will reach that last statement.
Edit: Solve some grammatical issues and other errors
Intuitively it works like this:
There is an infinite number of firms competing for the capital in the economy. If the rental price of capital $r$ is below its marginal product , then a firm can increase its profit by hiring more capital. In order to do this a $firm_1$ can offer a slightly higher rate than $r$ and immediatly all capital in the entire economy would go to $firm_1$, leaving all other firms with no production and thus no profit at all. But by that logic another $firm_2$ would offer an even higher rate that $firm_1$ and immediately all capital would go to that firm, leaving ...
I hope you get the picture. Firms compete for capital by offering an $r$ and that $r$ tends to $\partial f(k) / \partial k$ in a perfectly competitive market.
Obviously $r$ cannot exceed $\partial f(k) / \partial k$, because a firm would make losses and thus no firm is willing to offer an $r$ this high.