Mexico City is the capital of Mexico (the country). Toluca is the capital of the State of Mexico (one of 31 states). They're distinct entities despite geographic proximity.
As the federal capital, Mexico City is a unique entity—similar to Washington, D.C.—not part of any state. It's the nation's political, economic, and cultural center, with a metropolitan population exceeding 21 million.
Toluca serves as the administrative center for the State of Mexico, which surrounds Mexico City on three sides. The city sits at 2,680 meters (8,790 feet) elevation, making it one of North America's highest capitals. It's an important industrial and educational hub in its own right.
The State of Mexico and Mexico City share the "Mexico" name, and Toluca lies just 63 km (39 miles) west of Mexico City. The metropolitan areas nearly touch, creating a massive continuous urban zone.