The short answer: your Hamiltonian commutes with the parity operator. Therefore, the eigenfunctions which diagonalize the Hamiltonian can be searched within the eigenfunctions diagonalizing the parity operator, which are the sets of even and odd functions. Hence, you can use the condition $C=0$ to look for the odd solutions since $\sin(x)$ is odd, and $D=0$ to look for the even solutions since $\cos(x)$ is even.
This result is natural since the square well potential is even $V(x)=V(-x)$ and therefore we have
$$H\psi(x)=E\psi(x)$$
$$H\psi(-x)=E\psi(-x)$$
Using linearity, symmetric and antisymmetric combinations of eigenfunctions will also be solutions. These correspond to even and odd parity solutions respectively.
The long answer: the first thing I want you to note is that, as the Schrödinger equation is a second order differential equation, there are two boundary conditions. In this case, the usual choice is to solve the equation for Cauchy boundary conditions in which the value of the wavefunction and the derivative at boundary are specified. Hence you need to match
$$
\psi_I \left(-\dfrac{d}{2}\right)=\psi_{II} \left(-\dfrac{d}{2}\right)
$$
$$
\psi'_I \left(-\dfrac{d}{2}\right)=\psi'_{II} \left(-\dfrac{d}{2}\right)
$$
and similar at the right side $x=d/2$.
Considering the left side of the well, you get
$$ A \exp[-\kappa d/2]= C \cos(kd/2)-D\sin(kd/2)$$
$$ \kappa A \exp[-\kappa d/2]= k C\sin(kd/2)+kD\cos(kd/2)$$
Dividing both expressions, one gets
$$ \dfrac{\kappa}{k}=\dfrac{C \cos(kd/2)-D\sin(kd/2)}{C\sin(kd/2)+D\cos(kd/2)}$$
Performing the same calculation for the other side, we get
$$ \dfrac{\kappa}{k}=\dfrac{C \cos(kd/2)+D\sin(kd/2)}{C\sin(kd/2)-D\cos(kd/2)}$$
Equating both expressions gives, after some algebra, the condition
$$CD=-CD$$
which assures you that you can look for odd /even solutions separately since either $C$ or $D$ but not both must be zero.
Draw a coordinate system where $W$ (the particle energy) is on the horizontal axis. Then, do a plot of the left hand side of the equation. Then, the right hand side. The $W$ coordinate of the point where those two curves are crossing is the equation's solution; because there, the left hand and the right hand side of the equation are equal.
Of course, you need to know all the constants to draw the curves.
Here's a plot with all constants set to 1. The vertical lines don't really exist, it's just an artistical imagining by Mathematica.
![enter image description here](https://i.stack.imgur.com/D8Rbo.jpg)
Blue: left hand side
Red: right hand side
Best Answer
Inside the well, the wave functions of a bound state behave approximately like $\sin(kx)$ i.e. standing waves where $k=\pi M/d$ for an integer $M$. This contributes the kinetic energy $\hbar^2 k^2/ 2m$. The highest-lying bound states are those for which the energy left to the particle is $0-$, a small negative number, outside the well.
So the kinetic energy inside the well must be approximately equal to the height of the well $W_p$: $$ W_p = \frac{\hbar^2 k^2}{2m} $$ This implies $$ k = \frac{\sqrt{2mW_p}}{\hbar}$$ for the maximum allowed $k$ but I have mentioned that the spacing between the eigenstates in the $k$ space is $\pi/d$. So one has to divide the maximum $k$ above by $\pi/d$ to get the formula for $N$ you asked about.