When a swarm clusters, they send out scouts to find a new home. Sometimes they send them out before leaving the hive. When you put them in a box, the scouts may come and tell them they have a better place. If so, they are gone. If you keep the queen confined for 3 days, they usually forget the new home and stay in your box. If the scouts haven't found a place they like better, or you move them far enough that the scouts can't find them, then they usually stay.