The United States formed as a group of semi-sovereign political entities that wanted to make their own laws, but needed a common defense, foreign, and trade policy to prevent recolonization.
The founding fathers knew that the country wouldn't agree on everything, so they set up a system where a lot of decisions would be made by more local officials.
Other federations work on the same principle. It is a lot easier to get political consensus in a smaller group than a larger one, so a lot of decisions are pushed to more local entities.