Let's work this out in general. Suppose we wish to test whether $K = P(n)$, where $P(x)$ is a polynomial in $\mathbb{Q}[x]$. Assume there exists a polynomial $Q(x) \in \mathbb{Q}[x]$ and an integer $m \ge 2$ such that
$$ Q(K) \text{ is a perfect } m\text{th power } \iff \, K = P(n) \text{ for some } n\in \mathbb{Z}. $$
We will see that this places some very strong restrictions on $P(x)$.
From the $\impliedby$ direction, $Q(P(n))$ is a perfect $m$th power for all $n \in \mathbb{Z}$. By Hilbert's irreducibility theorem (or other methods), this implies that $$Q(P(x)) = R(x)^m$$ for some $R(x) \in \mathbb{Q}[x]$.
The left-hand side factors over $\mathbb{C}[x]$ into a product of factors of the form $(P(x) - \alpha_i)^{e_i}$ for each root $\alpha_i$ of $Q(x)$ with multiplicity $e_i$. These factors are pairwise relatively prime, so they must each be a perfect $m$th power in $\mathbb{C}[x]$.
We can assume that $e_i < m$ by dividing out any $m$th powers from $Q(x)$. The above then implies that $P(x) - \alpha_i$ is a perfect power (in $\mathbb{C}[x]$) for each $\alpha_i$. This implies that there are constants $a, b \in \mathbb{Q}$ such that $aP(x) + b$ is a perfect power in $\mathbb{Q}[x]$.
In other words, if there exists such a test that consists of checking whether a polynomial function of $K$ is a perfect $m$th power, then we can take the polynomial to be linear.
For the specific polynomial $P(n) = \dfrac{n(n+1)(2n+1)}{6}$, no such test exists since we there is no $a, b \in \mathbb{Q}$ such that $aP(n) + b$ is a perfect power. (In other words, "completing the cube" fails for this polynomial; the closest we can get is $24P(n)+1 = (2n+1)^3 -2n$.)
The above does not apply to the Fibonacci number test, both because $F_n$ is not a polynomial function of $n$ and also because it involves multiple polynomials. Could such a multiple-polynomial test exist for the square-pyramidal numbers?
Unfortunately this is not possible either, since at least one of the polynomial tests holds for a positive proportion of the $n \in \mathbb{N}$, which is enough for a stronger version of the Hilbert Irreducibility Theorem to apply, leading to the same conclusion.
Expanding on some fiddly details in response to the comments:
- We can choose $a,b$ to be in $\mathbb{Q}$ (even though $\alpha_i$ is, a priori, a complex number) because $P(x)$ is in $\mathbb{Q}[x]$; the idea is that the $k$th root of a polynomial is unique up to a constant factor, and the $k$th root algorithm keeps the coefficients of the root in $\mathbb{Q}$, provided the leading coefficient is a $k$th power. In a little more detail: Suppose $P(x) - \alpha_i$ is a $k$th power in $\mathbb{C}[x]$. Then so is $aP(x)-a\alpha_i$, where $a$ is chosen so that the leading coefficient of $aP(x)$ is monic. Write $aP(x)-a\alpha_i = S(x)^k$ where $S(x)$ is monic, then solve for the remaining coefficients of $S(x)$. If you do this you'll see that all of the coefficients of $S(x)$ must be rational (so in fact $\alpha_i$ must be rational as well).
- If $m$ divides all of the $e_i$, then $Q(x)$ is a constant times a $m$th power. In this case either $Q(K)$ is a perfect $m$th power for all $K$ (if the constant factor is a perfect $m$th power), or it is a perfect $m$th power for no $K$ (if the constant factor is not a perfect $m$th power), so here the test can only work in trivial situations (e.g. $P(n) = n$).
- The "in other words" rephrasing above needs more justification. Here we prove the stronger statement that $Q(x)$ cannot have more than one root: If $Q(x)$ has two distinct roots $\alpha_1$ and $\alpha_2$, then from the above we have that $P(x)-\alpha_1 = S_1(x)^{k_1}$ and $P(x)-\alpha_2 = S_2(x)^{k_2}$ for some $S_1(x), S_2(x) \in \mathbb{C}[x]$ and $k_1, k_2 \ge 2$. Subtracting the two equations, we get $$S_1(x)^{k_1} - S_2(x)^{k_2} = \alpha_2-\alpha_1.$$
The Mason-Stothers theorem states, for $\mathbb{C}[x]$, that if $a, b,$ and $c$ are relatively prime polynomials (at least one of which is not constant) with $a+b=c$, then $$\max\{\deg{a},\deg{b},\deg{c}\} \le \mathrm{rad}(abc) -1 $$
where $\mathrm{rad}(f)$ is the number of distinct roots of $f$. In this case the left-hand side is $\deg{P}$ while the right-hand side is at most
$$\frac{\deg{P}}{k_1} + \frac{\deg{P}}{k_2} - 1 \le \frac{\deg{P}}{2} + \frac{\deg{P}}{2} -1 = \deg{P} -1,$$
contradiction. So $Q(x)$ cannot have two distinct roots.
- For the stronger version of the Hilbert Irreducibility Theorem mentioned above see e.g. this MathOverflow post. Here is a simplified statement for this setting:
Let $f(X,Y)$ be an irreducible polynomial in $\mathbb{Q}[X,Y]$. Then for each $y_0 \in [-N,N]$, the specialization $f(X,y_0)$ is irreducible in $\mathbb{Q}[X]$ with at most $C\sqrt{N}\log{N}$ exceptions, for some constant $C$ depending on $f$.