Short Answer: We can't
Long Answer:
$\int_{-\infty}^{\infty}\cos(kt).dt$ as it is does not make sense. Plugging in infinity is not the same as plugging in a number
Perhaps if you said $\lim_{a\to -\infty, b\to\infty}\ \int_{a}^{b} \cos(kt).dt$ would be a little better.
But,
$$I = \int_{a}^{b}\cos(kt).dt = \dfrac{\sin(kb)}{k} - \dfrac{\sin(ka)}{k}$$
$\lim_{a\to -\infty, b\to\infty} I$ does not exist
Even if we consider the Cauchy Principal Value,
$$\lim_{n \to \infty} \int_{-n}^{n} \cos(kt).dt = \lim_{n \to \infty}\dfrac{2}{k}\sin(kn)$$
This limit again does not exist
Update after your edit
The Dirac delta version, arises in the distributional sense used in Fourier analysis. In distribution theory, we define the integral by its action on test functions.
We have $$\int_{-\infty}^{\infty}e^{ikt}.dt = 2\pi\delta(k) $$
From there $$\int_{-\infty}^{\infty}\cos(kt).dt = \dfrac{1}{2} . 2\pi\delta(k) + \dfrac{1}{2} . 2\pi\delta(-k) = 2\pi\delta(k)$$
Note: The Dirac Delta function is an even function.
Conclusion
The integral is undefined classically but defined in distribution theory as a functional, not a number.