Rearrangements happen only in SN1 and E1 reactions where there is a carbocation intermediate. They occur if a more stable carbocation can be formed.