If it’s a photoperiod, you have more flexibility. In most cases, it’s best to transplant first — if the roots are already circling or fully filling the pot, topping can stress the plant further. A smooth transplant into a larger pot gives the roots room to expand, and once it’s recovered and growing strong again, you can top. If the plant is getting too tall already, you can top sooner — just try not to stack both stressors at once. Let the plant’s condition decide the timing.
With autos it's risky, at least for me, some do the topping in a standard. Nonetheless, also let the plant/genetic decide. If you have something really small and fast, you'll probably cut into preflower or the genetic is small anyway