I know Lord Coke in Bonham's case (1610) had some dictum which might claim judicial review for a court, but that was controversial in 1610 and remains so (and never caught on in England). I also know Marbury v Madison and its progeny, and how for the most part judicial review has worked out pretty well for us. But I don't know its historical antecedents, if any. Was this somehow an Enlightenment idea that C.J. Marshall ran with? Part of the 'grand experiment'? Is the US still the only country to have it or did it develop in other places too?
Judicial review in the United States originates with a U.S. Supreme Court case called Marbury v. Madison. It was created in something of a brilliant way, and by doing so, paved the way for the U.S. Supreme Court to interpret whether Statutes comply with the Constitution ever since.
During my law school class where we studied this, it was presented that Chief Justice John Marshall quite likely knew that the young (at the time) U.S. Supreme Court had very little established power.
In Article III of the U.S. Constitution, the Supreme Court is created with limited jurisdiction. Congress is given the power to create lower courts, and the Supreme Court is only given jurisdiction to hear appeals from these lower courts. Thus, the matters that come before the USSC are very easily limited by Congress. The only other cases where the USSC has original jurisdiction are admiralty cases, cases involving diplomacy (ambassadors), cases that cross state lines, and cases where US States are themselves parties. This is a fairly limited scope, and takes the USSC a substantial distance away from the other two branches of government as far as power and authority, by my own estimation.
However, in 1803 William Marbury was appointed Justice of the Peace by president Adams. However, James Madison refused to deliver the commission documents, preventing Marbury from being able to take any official action as such.
Congress had created a Statute, namely the Judiciary Act of 1789 which allowed officers of the government to sue each other in Supreme Court and request Writs of Mandamus. Mandamus is essentially an order that says "You are supposed to do X according to Law, you have refused, now you must under threat of criminal sanction."
The approach that Marshall took to establishing judicial review was novel:
He noted that this new power of issuing a writ of mandamus was not in Article III anywhere. He also noted that Article III stated that congress could create lower courts to litigate other statutes, and that USSC could hear appeals from those courts, but not that the USSC itself could directly hear any new issues created by statute. He thus wrote an opinion that the 1789 Judicial Act created powers for the USSC that Congress was not allowed to actually grant, in violation of Article III of the Constitution. He then declined to issued the Writ for this reason, though he did note in the opinion that it appeared Marbury was, by all rights, entitled to his commission.
The interesting thing about this approach is that it was taken in the negative. Marshall declined to expand the Court's jurisdiction, and declined to utilize potentially new powers, thereby creating the ability of the court to abrogate congressional statutes by default.
Doing it this way was essentially un-challengeable. Who could appeal an opinion where the court declined to have jurisdiction over an issue? Who could challenge the text of the Constitution which so clearly supported Marshall's reasoning? Realistically, nobody.
And thus was born the concept of Judicial Review in the U.S.
Since then, Judicial Review has been defended by court opinions and scholars alike as Constitutionally implied and/or inevitable, though it is certainly subject to attack on a Constitutional basis. The Constitution does not give the USSC power to strike down statutes, and never has. However, when such a Statute is created, it falls to the President to enforce it and the Court to interpret it.
Interestingly, the USSC has lived by its limitation to appeal power ever since. You'll notice that a statute is never declared unconstitutional sua sponte (on the court's own initiative). Rather, the court must wait for some party to have a dispute that is brought up to it on appeal, or filed directly in the Supreme Court via one of the Constitutional direct jurisdiction avenues (admiralty, interstate, or ambassadorial).
Edit: To answer some of your more pointed questions, which I admit were neglected in the above:
As to why Marshall decided to opine this way is a matter of speculation. However, it was very likely political brilliance. Issuing a writ of mandamus the way Marbury was seeking would have been a political nightmare. The USSC had very limited power by comparison to the other branches, and as soon as it started ordering political officers around, fire would spread. Someone would eventually challenge the writs, and as they had no constitutional support, issuing one might well risk the stability of the young Government entirely.
Also, there was a very hot political war going on, which resulted in the sorts of disputes that lead to things like withheld commissions in the first place. I don't have a lot of understanding of the context, but there are some good sources out there that focus on things like the debates that James Madison was having with other officers of the government at the time.
Lastly, as to precedent, it's interesting to look at the case itself. Marshall does not directly cite very much, but does note the qualities of the Writ of Mandamus in English law, does cite Blackstone (one of the earliest legal textbooks ever written), and to some prior cases involving the U.S. Supreme Court. However, the best parts of the opinion seem to stem straight out of Marshall's own imagination. For instance, this very potent paragraph sums up his thinking:
*The intimate political relation, subsisting between the president of the United States and the heads of departments, necessarily renders any legal investigation of the acts of one of those high officers peculiarly irksome, as well as delicate; and excites some hesitation with respect to the propriety of entering into such investigation. Impressions are often received without much reflection or examination, and it is not wonderful that in such a case as this, the assertion, by an individual, of his legal claims in a court of justice; to which claims it is the duty of that court to attend; should at first view be considered 170 by some, as an attempt to intrude into the cabinet, and to intermeddle with the prerogatives of the executive.
That's a lot of fancy words to basically say: "The office of the president is a branch just as powerful, if not more so, than mine, and I don't want to get mixed up in this." Of special note is that this paragraph sits underneath an extensive analysis where John Marshall concludes that Marbury is very much entitled to relief, and his commission.
However, even at the conclusion of that line of reasoning, John Marshall still concludes that Marbury is entitled to Mandamus. It is only then that he enters into the analysis of whether or not his court has the authority to do it, and only after another long series of paragraphs, does he finally conclude:
It is emphatically the province and duty of the judicial department to say what the law is. Those who apply the rule to particular cases, must of necessity expound and interpret that rule. If two laws conflict with each other, the courts must decide on the operation of each.
In doing this, he really only cites the Constitution itself, and then goes into a philosophical analysis on fundamentals of what a court is supposed to be. In that regard, he seems to have just created the concept of judicial review on his own. His philosophical ramblings go on like so:
*“No person,” says the constitution, “shall be convicted of treason unless on the testimony of two witnesses to the same overt act, or on confession in open court.” Here the language of the constitution is addressed especially to the courts. It prescribes, directly for them, a rule of evidence not to be departed from. If the legislature should change that rule, and declare one witness, or a confession out of court, sufficient for conviction, must the constitutional principle yield to the legislative act? From these, and many other selections which might be made, it is apparent, that the framers of the constitution 180 contemplated that instrument, as a rule for the government of courts (emphasis his), as well as of the legislature.
He then concludes that by swearing an oath to uphold the constitution and the laws of the united states, it is the duty of a Judge to regard the constitution first, then the laws. He finds that there is simply no other alternative, and in this whole section of the case he just seems to be reasoning his way through it.
Hope that helps! Sorry for editing my post, I'm not very good at making a long one.