This is a special case of a formula given in the question "How can we sum up $\sin$ and $\cos$ series when the angles are in arithmetic progression?" and proven in the answers.
$$\sum_{k=0}^{n-1}\cos (a+k \cdot d) =\frac{\sin(n \times \frac{d}{2})}{\sin ( \frac{d}{2} )} \times \cos \left( \frac{ 2 a + (n-1)\cdot d}{2}\right) \tag{$\star$}$$
To match that notation, substitute $n\to k$, $N\to n$, $k\to p$ into the current relation, and rewrite a little. This is what the question is trying to show:
$$\sum_{k=0}^{n-1}\cos\left(\frac{p\pi}{4n}+\frac{p\pi}{2n}k \right)=\frac{\sin\dfrac{p\pi}2}{2\sin\dfrac{p\pi}{4n}}$$ Taking $d=\dfrac{p\pi}{2n}$ and $a=\dfrac{p\pi}{4n}=\dfrac{d}2$, relation $(\star)$ says that the sum should be $$\frac{\sin(nd/2)}{\sin(d/2)}\cos(a+(n-1)d/2)=\frac{\sin(na)}{\sin a}\cos(na)=\frac{2\sin(na)\cos(na)}{2\sin a}=\frac{\sin2na}{2\sin a}$$ Substituting $a$ gives the desired result. $\square$