The backstory of Sonic and his friends is best explored through dedicated fan documentaries and videos that trace the franchise from its 1991 debut onward.
Searching for a "history of Sonic the Hedgehog" video on a platform like YouTube is a great way to learn how the characters and their world came to be.