The stability of collective decisions-making in social systems is crucial as it can lead to counterintuitive phenomena such as collective memories, where an initial choice is challenged by environmental changes. Many social species face the challenge to perform collective decisions under variable conditions. In this study, we focused on situations where isolated individuals and groups of the American cockroach (Periplaneta americana) had to choose between two shelters with different luminosities that were inverted during the experiment. The darker shelter was initially preferred, but only groups that reached a consensus within that shelter maintain their choice after the light inversion, while isolated individuals and small groups lacked site fidelity. Our mathematical model, incorporating deterministic and probabilistic elements, sheds light on the significance interactions and their stochasticity in the emergence and retention of a collective memory.