We obtain thermostatted ring polymer molecular dynamics (TRPMD) from exact quantum dynamics via Matsubara dynamics, a recently-derived form of linearization which conserves the quantum Boltzmann distribution. Performing a contour integral in the complex quantum Boltzmann distribution of Matsubara dynamics, replacement of the imaginary Liouvillian which results with a Fokker-Planck term gives TRPMD. We thereby provide error terms between TRPMD and quantum dynamics and predict the systems in which they are likely to be small. Using a harmonic analysis we show that careful addition of friction causes the correct oscillation frequency of the higher ring-polymer normal modes in a harmonic well, which we illustrate with calculation of the position-squared autocorrelation function. However, no physical friction parameter will produce the correct fluctuation dynamics for a parabolic barrier. The results in this paper are consistent with previous numerical studies and advise the use of TRPMD for the computation of spectra.