What will be the value of $\cos (n\pi x /l)$ for $x=0$? $\cos0 = 1$ but the value of the above expression is $1$.  How it is equal to $1$?  If $\cos0 =1$ then the value should be $n\pi/l$.

Here we assume $l\neq 0$. If $x=0$, we have that
$$
\cos(n\pi\times 0)/l=\cos(0)/l=1/l.
$$
If you mean $\cos(n\pi x/l)$, then, at $x=0$, we have
$$
\cos(n\pi\times 0/l)=\cos(0)=1.
$$
