Those kinds of opinions are called advisory opinions and are allowed in some countries. Article III of the US constitution (which provided for the formation of the Supreme Court and the lower federal courts) requires that there be a "case or controversy" for the court to issue an opinion. This phrase is the basis for requiring a relevant case and not issuing advisory opinions.
The reason for this restriction traces back to John Jay, the first Chief Justice of the Supreme Court. Jay answered a request from President George Washington by stating that advisory opinions would violate the separation of powers between the three branches of government set up by the constitution. Muskrat v. United States (1911) expanded on this theory when the opinion said "The result will be that this court, instead of keeping within the limits of judicial power and deciding cases or controversies arising between opposing parties, as the Constitution intended it should, will be required to give opinions in the nature of advice concerning legislative action, a function never conferred upon it by the Constitution." Another reason to avoid advisory opinions is the simple fact that courts and judges have limited resources and courts can ensure that the available resources are conserved by requiring an actual case or controversy.