Courts are to interpret the law. The legislature says "all horses are animals." The courts have to answer "what about baby horses? dead horses? are things that are not horses also animals or can only horses be animals? is a zebra a horse? what about a horse embryo? who can decide what is a horse or not? etc etc." The courts have to answer these questions in such a way as to make life as least shitty as possible. So yes, the validity of shitty patents is totally up for the courts, but of course the legislature can weigh in any time.