If team A scores a basket in the last two minutes, Team B can obviously call a time out, then the ball can be advanced to the half court line for pass in.
However, as subs are allowed on made baskets (in the last two mins) and then team A calls a tim out ie they score a basket team b gets a sub, game is stopped Team A is allowed a time out. Team B doesn't get to advance the ball up the court, as it was not their time out.
It is only the team with the ball in their back court, who called the time out who can advance the ball.
You can use this in the last two minutes of the last quarter and subsequent extra periods, ie overtime.