Spike was always in love with Rarity, that was not something unknown to anyone, not even Rarity herself, despite Spike's efforts to not let it be known.
Contrary to what many believed, realizing that a relationship like this would be impossible was not a series of days of deep thought, but rather a simple night of thinking alone, which led Spike to notice a small detail that made that impossible. relationship, much to Twilight's happiness, but perhaps, also to her concern.