The story
The three ages come from three separate Heian court rites: at three a child's hair was allowed to grow, at five a boy first wore hakama, at seven a girl first tied an obi instead of cords. Edo-period commoners folded them into one shrine visit.
The day is a thanksgiving for a child having reached the age at all. The rites were kept when most children did not, and the odd ages were chosen because odd numbers are lucky.
