It starts in Sonic CD, when Sonic saves her from Metal Sonic.
That rescue is the origin of her attachment, and the games have kept it as a running joke ever since: Amy is persistent, Sonic is evasive, and neither actually changes. She is not a damsel in the usual sense either, since her Piko Piko Hammer makes her one of the more capable characters in a fight. The affection is genuine on her side and mostly deflected on his, which is the entire point of the pairing.