how do mining pools expose their stats? Webistes like https://miningpoolstats.stream/ must communicate with the pools somehow. What protocol do they use to retrieve information such as the pool's hashrate and what blocks have been mined by that pool? If I make my own pool what is the necessary API to expose this information?
Mining pools export this functionality via API's.

For example, poolin's API docs are here: https://btc.com/api-doc

Here's F2Pool's : https://www.f2pool.com/developer/api

And so forth. 

The way aggregators add value is by compiling all this data from different pools into a neat user interface.