As Hilmar mentioned, this is a phenomenon known as spectral leakage. The DFT is defined for all frequencies $[0,2\pi)$ that are periodic within $N$ samples. If the input signal is composed of frequencies that lie purely on the DFT sample points, then there will be no spectral leakage. This is because the DFT is an orthobasis expansion. If the signal is composed of frequencies that lie purely on the DFT sample points, then the signal is composed of the DFT basis functions, which will cancel out with all other non-matching basis functions when computing the DFT, and will add perfectly when matched with the correct basis function. If the signal is aperiodic within $N$ sample points, it is not composed of purely DFT basis functions, and will not add perfectly with any of the DFT basis functions, leaving residual values from the coherent summation in each DFT bin, known as leakage.
This is probably difficult to read, so I'll write out an example, but see more here on how the DFT is an orthobasis expansion. Let's let our signal be
\begin{equation}
x[n] = e^{j2\pi\frac{M}{N}n}
\end{equation}
where $N$, the number of sample points, is 3, and $M$ determines the digital frequency. For $M = 1$, i.e., our signal is purely composed of DFT basis functions, we get
\begin{align}
X[0] &= \sum_{n=0}^{2}e^{j2\pi\frac{n}{3}}e^{j0} = \sum_{n=0}^{2}e^{j2\pi\frac{n}{3}} = 0 \\
X[1] &= \sum_{n=0}^{2}e^{j2\pi\frac{n}{3}}e^{-j2\pi\frac{n}{3}} = \sum_{n=0}^{2}e^{j0} = 3 \\
X[2] &= \sum_{n=0}^{2}e^{j2\pi\frac{n}{3}}e^{-j2\pi\frac{2n}{3}} = \sum_{n=0}^{2}e^{-j2\pi\frac{n}{3}} = 0
\end{align}
Now let's let $M = 1.5$. Our signal is $e^{j2\pi\frac{1.5n}{3}} = e^{j\pi n}$. We then get
\begin{align}
X[0] &= \sum_{n=0}^{2}e^{j\pi n}e^{j0} = \sum_{n=0}^{2}e^{j\pi n} = 1 \\
X[1] &= \sum_{n=0}^{2}e^{j\pi n}e^{-j2\pi\frac{n}{3}} = \sum_{n=0}^{2}e^{j\frac{pi}{3}n} = 1 + j\sqrt{3} \\
X[2] &= \sum_{n=0}^{2}e^{j\pi n}e^{-j2\pi\frac{2n}{3}} = \sum_{n=0}^{2}e^{-j\frac{pi}{3}n} = 1 - j\sqrt{3}
\end{align}
So, as we can see, when $M$ is an integer, making it composed of one of the DFT basis functions, there is no spectral leakage. However, if $M$ isn’t an integer, making $x[n]$ not purely composed of basis functions, there will be spectral leakage into all other frequency bins.