The bar exam and law school have different purposes. A law school teaches the laws of the entire country. A bar exam tests the law of the specific state. While many laws are similar, they're not the same, and the differences matter a great deal.
And secondly, a great many people can eek their way through law school who have no business actually practicing law, and the bar exam is essentially the last filter keeping those incompetents away from the practice of law before they can harm clients. (The law provides recourse to clients when a lawyer's actions deliberately harms clients, however, there is little to no recourse for clients if their lawyer makes a mistake.)