Are stock exchanges market makers? Are stock exchanges like NASDAQ and NYSE market makers? In other words, are they providing liquidity by pairing individual buyers and sellers with each other in real-time? Or does it work differently?
No, they are not market makers.

A market maker is someone who (i) quotes two prices (one 'low' and one 'high'), (ii) will buy from any seller at the low quoted price (even if there is no corresponding buyer right now), (iii) will sell to any buyer at the high quoted price (even if there is no corresponding seller) right now.

This injects liquidity into the market when there is an imbalance in the number of sellers and buyers.

NASDQ and NYSE are not market makers, they are marketplaces in which market makers operate.