My textbook states that $$A^T = (SDS^{T})^{T} = (S^T)^TD^TS^T$$
where S is an orthogonal matrix and D is a diagonal matrix. But shouldn't it be
$$A^T = (SDS^{T})^{T} = S^TD^T(S^T)^T$$? Why and when are we allowed to rearrange the order of the matrices?
It's not rearrangement ; this relation is valid:
for any two matrices $A,B$.