Possible carbocation rearrangement in substitution reaction to give two different products
Is compound I formed by $\mathrm{S_N}$2 and compound II formed via $\mathrm{S_N}$1 after a carbocation rearrangement? Or is there some rearrangement I'm not aware of?

For the first question, the answer is probably not because the mechanism of a given reaction is mainly based on the condition used in the reaction (at least at the undergraduate level of teaching). The the answer for the second question is yes, you are unaware of the mechanisms called $\mathrm{S_N}$1' and $\mathrm{S_N}$2' (as Shoubhik R Maiti mentioned in the comments section). This type of reactions are common when the allylic compounds are the substrate, which is appropriately called allylic rearrangement or allylic shift. Allylic shift is possible under either $\mathrm{S_N}$1 or $\mathrm{S_N}$2 conditions, and commonly known with $\mathrm{S_N}$1' and $\mathrm{S_N}$2' notations, respectively.

Strictly speaking, if you have used condition favoring $\mathrm{S_N}$1 reaction, the intermediate is a resonance stabilized allylic carbocation. Thus nucleophile would attack at two positions (either carbon 1 or 3) to give the resulting products, I and II. For instance, see your reaction in a protic solvent ($\mathrm{S_N}$1), which would given the same type of product mixture (for convenience, I have used the labelling to show the difference):


Molecular modeling calculations would shows you the allylic secondary carbon position is more stable than the allylic primary carbon (recall your ab initio calculations for kinetic versus thermodynamic control in Org.Chem.II lab course; a simple and effective lecture demonstration of thermodynamic versus kinetic control, see: Ref.1) in intermediate carbocation. Accordingly, compound II would be the major product.

Similarly, if you are using the condition favoring $\mathrm{S_N}$2 reaction (strong nucleophile in a polar aprotic solvent) in this type of reaction, it is also possible to get two product due to $\mathrm{S_N}$2' mechanism. Usually, a bulky leaving group in $\mathrm{S_N}$2 conditions or bulky non-leaving substituent on the framework which give rise to significant steric hindrance would thereby increase the conjugate substitution ($\mathrm{S_N}$2'). Following scheme show the mechanism for two products:


Late Edit:
Since it seems OP is still cannot see how compound II is formed, I included the arrow-pushing mechanism for $\mathrm{S_N}$2 versus $\mathrm{S_N}$2' products:


References:

I. J. McNaught, &quot;Thermodynamic versus kinetic control: A lecture demonstration,&quot; J. Chem. Educ. 1978, 55(11), 722 (https://doi.org/10.1021/ed055p722.1).