Yes, market making is legal. It's not only legal, it's essential to the sound functioning of capital markets. Without professionals that offer competitive buy and sell prices, retail traders would have to pay far larger spreads on their transactions in order to buy and sell stock.
Like all traders, market makers can behave illegally. An SEC presentation highlighted one example where market makers control the float of a company and then adjust prices arbitrarily to their own benefit as a type of market manipulation. However, the act of market making itself is fine as long as participants stay within the rules and regulations of the SEC and stock exchanges.