As a disclaimer, it is worth noting that the reaction of an alcohol with thionyl chloride can proceed via multiple different mechanistic pathways (Wikipedia has a pretty good overview), depending on the conditions.
In the $\mathrm{S_Ni}$ mechanism a free carbocation is not formed; instead the key intermediate is an intimate ion pair $\ce{R+...^-OSOCl}$. This is not the same as a typical $\mathrm{S_N1}$ mechanism, where the leaving group is fully dissociated.
Following the formation of the intimate ion pair, the anionic component breaks down to form $\ce{SO2}$ and chloride ion, the latter of which attacks the cationic component $\ce{R+}$ to form $\ce{R-Cl}$. The reaction proceeds with retention of configuration, because the nucleophilic chloride ion originates from the leaving group $\ce{-OSOCl}$, and hence must attack from the same face as the leaving group left from.1

If the carbocation $\ce{R+}$ is allylic, then it is electrophilic at both the α-position (i.e. where the hydroxyl group started) and γ-position (i.e. two carbons away from the hydroxyl group). Therefore, following breakdown of the $\ce{-OSOCl}$ leaving group, the chloride can choose to attack either position. The attack at the γ-position is sometimes called the $\mathrm{S_Ni'}$ mechanism.

While the example above proceeds with extremely high selectivity for the rearranged product, this is not always the case. The above reaction was reported by Young in 1962,2 and carried out in dilute ether solution, which strongly favours the $\mathrm{S_Ni'}$ pathway. According to Gu and Zakarian in Comprehensive Organic Synthesis II (Chapter 6.16),3
Thionyl chloride has been used traditionally as the reagent of choice to ensure a high degree of selectivity in favor of allylic transposition, however, the outcome is often less predictable than desired. [...] The reaction, however, is often more complicated and dependent on reaction conditions and, to a greater extent, the structure of substrate. This is illustrated in the total synthesis of codeine reported in 2011. When allopseudocodeine was treated with thionyl chloride, a nearly equimolar mixture of regioisomeric products was produced.

References
Smith, M. B. March's Advanced Organic Chemistry: Reactions, Mechanisms, and Structure, 7th ed.; Wiley: Hoboken, NJ, 2013, pp 408–409.
Young, W. G. Unexpected rearrangement and lack of rearrangement in allylic systems. J. Chem. Educ. 1962, 39 (9), 455–460. DOI: 10.1021/ed039p455.
Gu, Z.; Zakarian, A. Functional Group Transformation via Allyl Rearrangement. In Comprehensive Organic Synthesis II; Knochel, P., Molander, G. A. Eds.; Elsevier, 2014; Vol. 6, pp 636–754. DOI: 10.1016/B978-0-08-097742-3.00624-8.