From a neoclassical perspectiveneoclassical perspective, its function is to allocate scarce resources efficiently, based on the invisible hand that make human selfishness work for the common good. Provided issues like externalities, public goods, etc are taking into account, every factor is paid its marginal product, ensuring efficiency.
From a Marxist perspectiveMarxist perspective, its function is to serve the capitalist class by exploiting the workers, who are forced to sell their labour in the market receiving a pay below their actual contribution (because, according to the labour theory of value, only labour produces value). The surplus is appropriated by the capitalists, who enjoy the benefits of the system.
These are not the only views of the function of capitalism that exist, but I think they are quite polar, providingIn my opinion these highly polar views provide the basis with which other, more complex views can be compared.