If a is rational, a=m/n, then it's easy to see that f is periodic, with period 2nπ.
It's harder to prove the converse. Suppose that f(x) is periodic. Then will also be periodic, with the same period. But when x=0, f(0)=f''(0)=0. If there is another point, say x=c, at which f(c)=f''(c)=0, and a≠±1, then you should be able to show that sin(c) = sin(ac) = 0. With c≠0, this is only possible if a is rational. But if there is no such point c then f cannot be periodic.
See my previous comment (#4 above). If is periodic, with period c, then . The second derivative will also be periodic with period c, and therefore . Add those two equations together, and you see that . Assuming that , it follows that . Since , it also follows that .
But if then x must be a multiple of π. Therefore both c and ac are multiples of π, say c=nπ and ac=mπ. Then a=m/n, which is rational.