There are a couple of reasons for this. First of all there are certain disclosure rules that companies have to be aware of when announcing earnings. Basically all investors who want the information should be able to get access to it before any trading takes place.
If there isn’t a grace period to give everyone time to receive the information and they just announced it during market hours, then a few insiders or a few “early bloomers” would have an unfair advantage and could in theory use that information to profit before the general public knows anything about it.
The second reason is to just avoid mass hysteria. If a company’s earnings was say, just under what it was expected and they announced it during the trading day, there would be mass panic selling in the markets shortly after the announcement.
Giving people a grace period also helps them to calm down and think things through before making a rash decision based only on their emotions alone.