As $E$ is always positive, your $k_1$ is imaginary. It incorporates the $i$ that is visible in the second solution. They are really the same solution, with $k_1=ik_2$. If your square well is finite, outside the well we have $E \lt V$ and the $E$ in your solutions becomes $E-V$. Then the first solution has real $k_1$ and represents the tunneling into the walls.
The potential you have written is perfectly legitimate, let's do the derivation from scratch:
$$ V(x) =
\begin{cases}
-V_0&0<x<b \\
0&b<x<a \\
\infty&x>a \\
\end{cases}$$
and $V(-x) = V(x)$ the Hamiltonian will commute with the parity operator $[\hat{H},\hat{\mathscr{P}}] = 0$, therefore the eigenstates of the energy will be eigenstates of the parity operator too. Also, we can solve the problem in the interval $[0,a]$ with $b<a$ since the eigenfunctions of $\hat{H}$ are parity eigenstates too. Now and this is the most important thing: an infinite well can ONLY have bound states, so we have to look for bound states of the infinite well and adapt this fact to work with the finite well inside (which adimts "scattering" (positive energy) states). This basically means that $E>0$ (you can easily check that if you started from the condition to get the bound states inside the finite well you would get an impossible condition for the infinite one at the point $x=a$)
Region $[0,b]$:
The Shrodinger equation is $$-\frac{\hbar^2}{2m}\nabla^2\psi-V_0\psi= E\psi$$ with $V_0>0$ in one dimension the solution will be: $$\psi_+(x)=C_1 cos(\omega x)\\ \psi_-(x)=C_1 sin(\omega x)$$ we will work with parity $+$. for comodity. With $\omega=\sqrt{\frac{2m}{\hbar^2}(V_0+E)}$.
Region $[b,a]$:
Here the Shrodinger equation is:
$$\frac{\hbar^2}{2m}\nabla^2\phi= E\phi \\ \phi(a)=0$$ notice that $\phi(a)=0$ is the foundamental condition that "tells" the particle that there is an infinite well, and this condition is also the reason that $E>0$ infact if $E<0$ you would have $\phi_+= A_1 \cosh(kx)$ which only has immaginary solutions for $\phi(a)=0$ or the useless $k=0$. The solution for $E>0$ here will be:
$$\phi_+(x)=A_1 cos(k x)\\ \phi_-(x)=A_1 sin(k x)$$
with $k=\sqrt{\frac{2m}{\hbar^2}E}$, now since $\phi_{\pm}(a) = 0$ we have that $k$ must be: $$k_+=\frac{(2n+1)\pi}{2 a} \\ k_-=\frac{n\pi}{a} $$.
Now we have to match the solutions in $x=b$. (we have to match the derivatives too since the general solution must be $C^2$)
$$\psi_+(b)=\phi_+(b) \\ \psi'_+(b)=\phi'_+(b)$$ this leads to (for the parity even eigenstates):
$$C_1 cos(\omega b) = A_1 cos(k b)\\ C_1 \omega sin(\omega b) = A_1 k sin(k b)$$
The solution reads: $$\tan(\omega b) = \frac{k}{\omega} \tan(k b) $$ which can be written as : $$\tag 1 \omega \tan(\omega b) = \frac{(2n+1)\pi}{2a} \tan\left( \frac{2n+1}{2a}\pi b \right)$$
Now, if you do $b \rightarrow a$ you get that $\tan\left(\frac{2n+1}{2}\pi\right) \rightarrow \infty$ which means that $cos(\omega b)=0$ which means that $\omega = \frac{2n+1}{2 b}\pi $ (also $k$ vanishes) which is the usual energy for the infinite well.
The limit $b \rightarrow 0$ is consistent too. Consider equation $(1)$ written as $$\omega=k \frac{\tan\left(kb\right)}{\tan\left(\omega b\right)}$$ now take the limit $b \rightarrow 0$ on both sides $$\ \omega = k\cdot \frac{k}{\omega}\longrightarrow \omega = k$$ and you are left with $k = \frac{(2n+1)\pi}{2 a}$ which is the usual infinite well energy.
Best Answer
Short version:
In the infinite potential well, $E \geq 0$ (because $V_{min}=0$, and $E \geq V_{min}$). In your finite potential well, it sounds like you are looking for bound states, in which case $E < 0$, so you absorb the negative into the square root.
Long version:
When you are tackling a QM problem, first you should figure out the admissibility of bound states and scattering states. If the energy of the particle is less than the potential at $-\infty$ and $+\infty$, then you have bound states. For example, the infinite square well only admits bound state solutions. The finite potential well can admit both scattering states and bound states depending on the energy (typically, $V(\pm \infty) = 0$ in a finite potential well, so if $E < 0$ it is a bound state and if $E > 0$ it is a scattering state).
Once you declare whether you are seeking bound or scattering states, you will have an idea of where your energy is. In the finite square well with $V(\pm \infty) = 0$, if you are seeking bound states, then you know $E < 0$. Therefore, to keep the math as straightforward as possible, it makes sense to place the negative in the square root so the argument will be positive.
In the infinite square well, you know that all states are bound because $V(\pm\infty)=\infty$. So we must appeal elsewhere to get a constraint on the energy. We know that $E \geq V_{min}$ (otherwise the wave function cannot be normalized, see Problem 2.2 of Griffith's QM). Since $V_{min}=0$, then $E \geq 0$. Therefore, we should not absorb a negative into the square root to keep the argument positive.