They use DGT/Electronic chess boards which give out information about the position, and the clocks also give out their data. I don't know how chess.com gets the data from events they do not host, like the recent world rapid championship (Maybe they make a deal with Fide or something), but I do know that lichess has an endpoint: https://lichess.org/api#tag/Broadcasts/operation/broadcastTourGet
Under https://www.chess.com/events, if any event is going on, chess.com will show the live games. How are the moves and clock times determined in real time? Is there an external API to get this information?