I have found similar questions in this forum but those answers didn't specifically clear the fact.
Usually there is a limit order book, so any market order that comes in matches against the existing limit orders in the book. As an exchange matches orders one at a time, it is likely that they will always match a market order against an existing limit order.
One of the problems with executing two market orders against each other is determining what the execution price would be.
Some exchanges (for example, IEX, the Investors Exchange) offer a midpoint order type, which effectively places a hidden limit order at the midpoint between the bid and ask. This in turn will execute against any other midpoint orders (or market orders) submitted.
In implementing my own matching engine, this was one of the edge cases I had to consider - what happens if someone submits a market order if there are no existing orders in the book? Potentially a market order could sit there. However if another market order came in, how would you determine the execution price?
Exchanges deal with this situation by requiring that market orders be marked or are implicitly marked as "immediate or cancel" (they should be unlikely to be cancelled), and process incoming orders one at a time.
That is not to say that an exchange could file with the SEC that they are going to offer market order matching and outline the process for doing it (e.g. allowing submitted market orders to hang around at the midpoint for a second before executing against the limit order book). However there would have to be sufficient demand for such a feature, but some people might get upset if their orders are taking a second to get filled even if it is at a better price, so could submit negative comments on the proposal.