It is, of course, possible to price such a contract in a no-arbitrage market. Indeed, if $f$ is a sufficiently smooth function, then you can price all contracts paying $f(S_T)$. Note that your specific payoff has no optionality and that the payoff may be negative. Bakshi and Madan (2000) discuss the economic meaning of a derivative paying $\cos(S_T)$ in the context of market completion and characteristic functions.
You have many different ways of solving the pricing problem:
Standard risk-neutral pricing
Look at the simpler case of the time zero price
\begin{align}
\Pi(0;X) &= e^{-rT}\mathbb{E}^\mathbb{Q}[\cos(S_T)] \\
&= e^{-rT}\int_\mathbb{R}\cos(x)f_{S_T}^\mathbb{Q}(x)\mathrm{d}x \\
&= e^{-rT}\int_0^\infty \cos(x)\frac{1}{x\sqrt{2\pi\sigma^2T}}\exp\left(-\frac{1}{2}\left(\frac{\ln(x)-\ln(S_0)-\left(r-\frac{1}{2}\sigma^2\right)T}{\sigma\sqrt{T}}\right)^2\right)\mathrm{d}x
\end{align}
In the standard put/call case, the substitution $\xi=\frac{\ln(x)-\ln(S_0)-\left(r-\frac{1}{2}\sigma^2\right)T}{\sigma\sqrt{T}}$ with $\mathrm{d}x=x\sigma\sqrt{T}\mathrm{d}\xi$ concludes the computation, i.e.
$$ \Pi(0;X) = e^{-rT}\int_\mathbb{R} \cos(x)\frac{1}{\sqrt{2\pi}}\exp\left(-\frac{1}{2}\xi^2\right)\mathrm{d}\xi.$$
In your case, the integral may be a bit harder to compute due to the additional $\cos(x)$ term, where $x=\exp\left(\xi\sigma\sqrt{T}+\ln(S_0)+\left(r-\frac{1}{2}\sigma^2\right)T\right)$.
Carr Madan Static Replication Formula
Assuming you know how to price call options in your chosen model (easy in the Black Scholes case), we can use the following formula
\begin{align*}
f(x) &= f(a) + f'(a)\cdot \left( (x-a)^+ - (a-x)^+ \right)\\
&+ \int_0^a f''(\kappa) (\kappa-x)^+ \mathrm{d}\kappa+ \int_a^\infty f''(\kappa) (x-\kappa)^+ \mathrm{d}\kappa,
\end{align*}
which holds for any sufficiently smooth $f$ and for any $a\geq 0$. This expresses a payoff function $f$ in terms of the payoff function of puts and calls. Using $f(x)=\cos(x)$ and $a=0$, we get
\begin{align*}
\cos(x) &= 1 - \int_0^\infty \cos(\kappa) (x-\kappa)^+ \mathrm{d}\kappa \\
\implies \Pi(t,X) &= e^{-r(T-t)}-\int_0^\infty \cos(\kappa)\mathrm{Call}(S_t,\kappa,T)\mathrm{d}\kappa,
\end{align*}
where $\mathrm{Call}(S_t,\kappa,T)$ denotes the Black Scholes price of a European-style call option with strike price $\kappa$ and maturity $T$. You end up with an integral which may be hard to analitically compute, but it is very easy to approximate the integral with arbitrary precision.
Standard Numeric Algortihms
It is very easy to find the price of this claim using Monte Carlo simulations.. Just simulate realisations of $S_T$ and apply the cosine function to the terminal stock price. Then, you know your future payoff which you merely need to discount and average. Of course, you can also employ other numerical techniques such as trees and Fourier methods.
Look at this brief R
example of a Monte Carlo simulation
tau = 1 #Time to maturity
s0 = 1.75 # initial stock price
sigma = 0.1 # volatility p.a.
r = 0.1 # interest rate p.a.
nSim = 1000000
Z <- rnorm(nSim, mean=0, sd=1)
WT <- sqrt(tau) * Z
ST = s0*exp((r - 0.5*sigma^2)*tau + sigma*WT) # terminal stock price
simulated_payoffs <- exp(-r*tau)*cos(ST) # discounted payoff
price <- mean(simulated_payoffs)
You'll see that the price is negative. This is impossible for put and call options due to their optionality but quite possible for your claim paying $\cos(S_T)$ since the payoff itself may be negative...