The question is the same as asking when are the solutions to the Schrodinger equation of the form $\psi(x)=A\sin(kx)$ or $\psi(x)=Ae^{\kappa x}$.
Assume $\psi(x)=A\sin(kx)$ is your solution with $k$ constant but an unknown $V(x)$ and plug into the Schrodinger equation
\begin{align}
-\frac{\hbar^2}{2m}\frac{d^2}{dx^2}A\sin(kx) + V(x)A\sin(kx)&=EA\sin(kx)\, , \\
\frac{\hbar^2k^2}{2m}A\sin(kx)+V(x)A\sin(kx)&=EA\sin(kx) \tag{1}\, .
\end{align}
Since (1) must hold for every $x$, and assuming $A\sin(kx)\ne 0$ for some $x$, we can cancel the common factor $A\sin(kx)$ for this $x$ and are left with:
$$
V(x)=E-\frac{\hbar^2k^2}{2m}\, .
$$
In other words, the potential is constant: $V(x)=V_0$. Reorganizing we get
$$
\frac{\hbar^2k^2}{2m}=E-V_0\, .
$$
Since the left hand side is necessarily positive, the $\psi(x)=A\sin(kx)$ can
only occur when $E-V_0>0.$
The same manipulations repeated with $\psi(x)=Ae^{\kappa x}$ yields
$$
V(x)=E+\frac{\hbar^2\kappa ^2}{2m}\, ,
$$
also showing the potential is constant. This time however one concludes that
$$
\frac{\hbar^2\kappa ^2}{2m}=V_0-E
$$
so that this solution can only occur then the potential is greater than the energy.