You could argue it was inevitably going to happen since Apple started designing their own silicon. iOS is macOS, more or less (modulo a few system libraries and apps), so since the beginning of the iPhone project, Apple has had the software in place to make an ARM-based Mac if they wanted to.
Could you please expand on that? I heard they were quite distinct, e.g. sandboxing/security is done completely differently, with ios having a much more modern approach.
While pedantically it can be included in your modulo, but are they really that similar?
What I mean is that iOS is a fork (or, I suspect, maybe just a build configuration) of macOS. Since it was a new platform, Apple could try some new things and enforce new restrictions (like sandboxing), but they're not completely different codebases in the way that Windows CE and Windows NT are. The core technologies are the same at most levels of the OS and, if they're not maintained a single codebase, clearly many components are.
Therefore I strongly suspect that Apple had macOS running on the iPhone and iPad from very early on. They just did not want to release it because the UI is not suited to a phone.
When presenting the original iPhone Steve Jobs announced that it ran OS X. I'm not sure how far apart they've grown but at that point they were probably very similar.