Who determines whether tax has public purpose?

The short answer is "Congress" However, that would be an incomplete answer; there is a long answer.

While it is true that Congress enjoys the power to levy taxes, taxation being inherently legislative in character, and that it is Congress which has the power to set the purpose for which the same are collected from the people, the Presidency, using its veto powers, can also legally delay a bill in its way to becoming a law if it perceives that there is no public purpose. Moreover, the Constitution grants the Supreme Court the power to determine whether there has been grave abuse of discretion on the part of Congress in enacting a law. Abuse of discretion may be in the form of passing a tax law without a public purpose.