How do central banks earn profit?
Central Banks are not made to make profit. They are there to stabilize the price (inflation) and avoid crisis.

But to do that, they sell and buy assets. If they do a good job, they must purchase assets when they are undervalued and sell when they are overvalued. By doing that they are making profit.

This is good because Central Bank's infrastructure does have a cost. If they were not making profit, they would have to be financed by the taxpayer. When a central bank is making profit, they typically give this money back to the state, lowering the amount of needed taxes.