Outlook simply connects to exchange. You can buy and run your own exchange email server. People have done it for years.
Gmail handles the spam filtering because the protocol hasn’t changed since the 70s. It is the same protocol since then. It basically evolved to have spam lists and deliverability ratings based on necessity. Deliverability is impacted by many things including those outside of your control like your neighboring ip addresses. It’s not hard. Just super tedious.
As others have said email is already federated but like most federated things to make it not a shit hole in today’s world is a lot of work.