The cost is justified due to a common shared interest in the subject, many other people are interested in math and pay people to work on it. It's not all that different than paying someone for music, or a painting, or to write a work of fiction. People get a profound sense of enjoyment and happiness from this work and are happy to pay the cost for the continued advancement of this field.
> k = x³ + y³ + z³ is what number theorists call a Diophantine equation — a kind of algebraic structure whose properties have fascinated mathematicians for millennia. “They’re rich enough to encode [other mathematical] statements that have nothing to do with Diophantine equations,” said Browning. “They’re rich enough to simulate computers.”
More specifically, equations of such form come up in a proof of Godel's first incompleteness theorem. That being said, yeah, this effort is mostly a mathematical curiosity, mapping out the domain of knowledge of mathematics increasingly more completely. Sometimes an application comes about where either the solution or novel techniques used to arrive to the solution can become useful, but pure math research isn't typically driven by any existing applications as much as a "because it's there" attitude.