In chapter 12, Samuelson begins to outline the answer to your question. Costs come from factor prices and factor prices are determined according to marginal productivity theory.
This sounds like the Austrian position. However, the Austrian view accounts for actual time. Today entrepreneurs anticipate consumer demand and the price of the consumer good that will emerge in the future when the good is sold and, based on that future price, entrepreneurs demand factors of production accordingly. The factor prices are determined today by the overall entrepreneurial demand for factors (which depends on their anticipated marginal revenue product) and supply by factor owners. The prices of consumer goods today are determined by entrepreneurial supply (which is unrelated to either factor prices today or the cost of production of the goods in the past) and consumer demand today.
In contrast to this causal-realist view, neoclassical price theory is timeless. Consumer demand (based on consumer utility) and producer supply (based on costs of production) are assumed to exist synchronously. In partial equilibrium, the price of the consumer good is jointly determined by demand and costs of production. In general equilibrium, all prices of goods and factors are perfectly adjusted to each other (every price is jointly determined by every other price). There is no cause and effect in time, but only mutual determination moment-to-moment.