Why is there a commandment to have a king if we have a Sanhedrin?
The king was in charge of national issues, like today's government, e.g. economy, security, welfare etc., while the Sanhedrin decides on questions of halacha, e.g. monetary disagreements and "religious" issues like Shabbat, Kashruth, Purity etc. (although really, the economic and military welfare of Israel are also religious issues!). In addition to the different fields of responsibility, there also was a "checks and balance" system of accountability between the king and Sanhedrin. There also was a third "side" of the triangular leadership system, which was the navi/prophet (to rebuke the nation, king & Sanhedrin) and Kohen Gadol (who ran the Beit HaMikdash and played a more universal role, vis a vis the nations of the world), who both had a "direct line" to G-d.