The necessary and sufficient condition is that there exists $n$ such that $|a_k|=O(|k|^n)$; that is, the coefficients are of at most polynomial growth. This applies to both $\mathcal D'$ and $\mathcal S'$ equally, since for periodic distributions the "tempered" property brings no additional restriction: they do not grow at infinity anyway.
Sufficiency: if $|a_k|=O(|k|^n)$, let $b_k = a_k/(ik)^{n+2}$ for $k\ne0 $ (and let's say $b_0=0$). Then $\sum b_k e^{ikx}$ converges uniformly, so it defines a continuous periodic function $f$ (hence a tempered distribution). Since the derivative is a continuous operation with respect to distributional convergence, any convergent series of distributions can be differentiated term by term. Doing this $(n+2)$ times, we get the original Fourier series (up to a constant). Its sum is $f^{(n+2)}$, understood as a distributional derivative.
Necessity: Every distribution is of finite order on a compact set, hence can be expressed by differentiating a continuous function a bunch of times (mentioned here, for example). The Fourier series of a continuous function has bounded coefficients. Translating this to the derivatives, we get a polynomial bound on the Fourier coefficients.