The answer to your question lies in simple dimensional analysis.
Joules are the units of energy, so also the units of work. Work, as we all know, satisfies the relationship $$W=\vec F \cdot \vec s$$ Meanwhile, $$\vec F= m \vec a$$ Substituting in this relationship gives us $$W=m\vec a \cdot\vec s$$
Now, let's look at the units of this equation: $$[\text{J}]=[\text{kg}][\text{m}]^2[\text{s}]^{-2}$$
Clearly, then,
$$ [\text{J}][\text{kg}]^{-1}=[\text{m}]^2[\text{s}]^{-2}$$
and both units are equivalent: $c^2=(299792458)^2\ \text{J}\ \text{kg}^{-1}$
The reason why we can invoke these unrelated equations to analyze the dimensions of the quantities involved is because every expression in physics must be consistent (dimensionally), so in terms of units they all express the same things, and we get to pick whichever is simplest to solve our problem.