thermal equilibrium and the CMB

Why does the CMB have a Planckian spectrum? After all, it has been generated over a range in redshift (\(\Delta z\simeq 100\)) over which the temperature changed, and there has been energy exchange with the electron plasma.

bonus question: Can you show that the asymptote of the integral sine, \(\int_0^x\mathrm{d}\ln(t)\:\sin(t)\), is \(\pi/2\) for \(x\rightarrow\infty\)?