Motivated by optimal investment problems in mathematical finance, we consider a variational problem of Neyman-Pearson type for law-invariant robust utility functionals and convex risk measures. Explicit solutions are found for quantile-based coherent risk measures and related utility functionals. Typically, these solutions exhibit a critical phenomenon: If the capital constraint is below some critical value, then the solution will coincide with a classical solution; above this critical value, the solution is a superposition of a classical solution and a less risky or even risk-free investment. For general risk measures and utility functionals, it is shown that there exists a solution that can be written as a deterministic increasing function of the price density.