As it is said that lord Hanuman was very mischievous during his childhood. One day he saw Sun through the leaves of a tree and thought of it as a fruit, so he flew in order to eat it.
It has nothing to do with any curse. Rather, he was hit by Indra's vajra when he refused to release Surya and later on was given many boons by different Gods.
Source: Hanuman Chalisa by Goswami Tulsidas .
जुग सहस्र जोजन पर भानू।
लील्यो ताहि मधुर फल जानू॥ १८ ॥
The Sun is at thousand yojanas (a unit of measurement of distance), and thought of it as a sweet fruit.
Source :Sankatmochan Hanumaashtak
बाल समय रवि भक्षी लियो तब,
तीनहुं लोक भयो अंधियारों ।
ताहि सों त्रास भयो जग को,
यह संकट काहु सों जात न टारो ।
देवन आनि करी बिनती तब,
छाड़ी दियो रवि कष्ट निवारो I
During your childhood, you engulfed the Sun and it caused darkness in three worlds (Swarg, Prithvi, Pataal)
The worlds were in havoc, this panic was not controlled by anyone.
Gods came to you and prayed(requested), then you let Sun go free and eased the problem.