And then the nuclei return to the ground state. That process is probabilistic and measured in half-lives. The key point is that the decay back to ground state happens at a very precise rate that is not influenced by effectively anything, and can be measured accurately. Thus, a clock.