At all times the market maker posts 2 prices: the bid and the ask (which is higher than the bid). When someone sells to the marketmaker, they receive the bid price, when someone wants to buy they have to pay the ask price. So the market maker earns the spread between these two prices, just like a street vendor sells you an apple for a higher price than he paid at the wholesale fruit market - that is his profit.
The hedging makes it possible to eliminate the "inventory risk" i.e. the danger of price changes between the time the marketmaker buys from X and the time he sells to Y. But the profit comes (mostly) from the price difference.