It's possible because t and t' mean different things in the two equalities. Consider two inertial coordinate systems S and S' with a common origin. Denote the velocity of S' in S by v. We assume that v>0. Denote the event at the origin by O. Let E be an event on the time axis of S, and denote the time coordinate of E in S by t. Now the time dilation formula tells us that t'=γt. Here t' is the time coordinate of E in S'. Note that E is not
on the time axis of S'.
But when you use the time dilation formula to go from S' to S instead, t' is the time coordinate of an event F on the time axis of S', and t is the time coordinate of F in S. So we're not just doing the calculation we did before "in reverse". It's a calculation that involves a different event.
This is what I said about the apparent contradiction in another thread: