I think it is coincidence, apart from that there may be anthropic arguments for the spin axis inclination (the difference between the spin and orbital axes) to be small but non-zero. i.e. A small, but non-zero inclination is favourable for habitability.
In a previous version of this answer (and I acknowledge that @sno's contribution has made me think a bit harder), I pointed out that the vorticity (see below) of a fluid rotating on circular orbits with a Keplerian velocity profile $v \propto r^{-1/2}$ would favour the accretion of planets with a small orbital inclination. This may well be a factor in the accretion of gas giants.
However, this initial "fluid" phase is only part of the story for the accretion of the terrestrial planets. This will only result in the formation of small planetesimals and indeed, simulations suggest these would predominantly have prograde, aligned rotations (Johansen & Lacerda 2010; Takaoka et al. 2023). The main phase of mass accretion takes place after the gas/fluid has been removed and there is then a very chaotic phase of accumulation (and destruction) of these planetesimals. The orbits become much more eccentric and highly inclined and the final phases of planet construction will consist of a bombardment of a planetary embryo from all directions. The final spin angular momentum of the planet will be dominated by the final few collisions and merger of relatively large bodies, like the collision that probably formed the Earth-Moon system (e.g., Agnor et al. 1999; Agnor 2002).
What all this means is that the orbital inclinations of the terrestrial planets are likely to have been almost random after formation. Examples of simulations that show the spin-axis inclination is essentially random (an isotropic distribution) are provided by Kokubo & Ida (2007); Kokubo & Genda (2010). It is fair to say though that others disagree - arguing that the current terrestrial planets do at least contaim some memory of the initial prograde spin of the smaller planetary embryos (Visser et al. 2020).
Subsequently there are tidal influences that can play a role - either from the Sun or in the Earth's case, from the Moon. However, the timescale on which the spin-orbit alignment can be changed is similar to the timescale upon which the rotation period of a planet is synchronised with its orbital period. Clearly this hasn't happened for the Earth but it probably played a major role in Mercury's zero spin inclination (e.g., Noyelles et al. 2014).
A factor that is worth mentioning is that the small but non-zero (23.5 degrees) obliquity of the Earth's spin to its orbital axis may be a coincidence, but it could be that we observe it to be that way because it is important for our existence (an anthropic argument). The spin inclination of Earth is stabilised by the Moon and ensures a relatively small variation in temperature across the globe and drives the seasons. A very high inclination or a very low inclination may well not be favourable to life (see the introduction in Heller et al. 2010).
Vorticity
If a collection of particles or a fluid coagulates, then the direction of rotation will be given by the vorticity, which is the curl of the velocity vector field.
The planets formed in a flattened protoplanetary disc around the Sun, which accounts for their common direction of orbit and roughly planar geometry. For circular Keplerian orbits around the Sun, the velocity field is
$${\bf v} = \left( \frac{GM_\odot}{r} \right)^{1/2} \hat{\phi} $$
and the vorticity is
$${\rm curl}\ {\bf v} = \frac{1}{r} \frac{\partial}{\partial r}\left(r v_{\phi}\right)\ \hat{z} = \frac{1}{2}\left(\frac{GM_\odot}{r^3}\right)^{1/2} \hat{z}\ . $$
The direction of this vorticity (i.e. the sense of the spin) is in the same direction as the angular momentum vector of the orbit, given by
$$ {\bf L} = m{\bf r} \times {\bf v} = mrv_\phi\ \hat{z}\ . $$
If the tangential velocity component of the fluid depends on $r^{\alpha}$ then the vorticity will be in the same direction as the angular momentum as long as $\alpha > -1$. It is zero if $\alpha = -1$ and in the opposite direction to the orbital angular momentum of $\alpha < -1$. In this case we have $\alpha = -0.5$.
In reality, protoplanetary discs do not rotate in such a uniform fashion. They can be unstable to the formation of large scale patterns and vortices that complicate the planetary formation process. There is also the possibility of fairly random catastrophic collisions between larger bodies near to the end of the accretion process.