What is the purpose of the judicial branch deciding on laws?
The purpose of the judicial branch deciding on the legality or constitutionality of laws is to ensure that a branch of government that did not create the laws is passing judgement on them. For Congress to decide whether or not the laws it created are legal and constitutional is like having students give themselves their own grades. Of course they are going to say the laws are fine. They wrote them! Someone or some entity outside the legislature is able to judge this more fairly and dispassionately. It is possible, I suppose, that this function could have been given to the executive branch. But had we done that, we would have had just one person, someone who was likely to have his own political agenda, passing judgement on the laws. The idea was to have nine people's opinions on the matter, resulting, it was hoped, in a fairer, more knowledgeable, and less politicized decision, at least in theory. With an uneven number, there could not be a tie, and thus at least five people, as opposed to one person, would be ruling on the laws Congress passed. This is a check on the power of the legislative branch, whom we do not want to make laws that take away any of our rights under the Constitution or otherwise undermine any of the principles that the Constitution stands for.