Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
I found an actual scriptural account of the story the other two answers describe, from the Uttara Kanda of the Ramayana.
As a child, Hanuman acquired lots of boons from various gods, as I describe in this answer. And he started using his new-found powers to cause a lot of mischief:
Because of the boons he received and the strength which he gained from them, Hanuman was replete with his own speed, like the ocean. Overflowing with energy, Hanuman fearlessly desecrated the hermitages of great sages. He broke the sacrificial laddles and vessels, interrupted the offering of oblations into sacrificial fires and tore up the piles of bark cloth belonging to the peaceful sages. The mighty Hanuman continued doing such deeds. Knowing that Brahma had made him invulnerable to punishment by brahmanas, the sages tolerated it because of his power.
Although prohibited by [his fathers] Kesari and Vayu, Hanuman went beyond the bounds of propriety. Great sages born in the families of Bhrigu and Angira, who were never overly angry or wrathful, became furious and cursed him in the following way: "O monkey, illusioned by our curse, you will for a long time be unaware of your own strength, by dint of which you harassed us. Your strenth will again grow when you are reminded of your glory." Thereafter, by the power of the words of the great sages, Hanuman was deprived of his strength.
That curse is what caused him to forget his powers.
You also asked whether Hanuman has the power to genuinely fly. I think the answer is yes, because Jambavan tells him that he has the same powers of flight as his father Vayu the wind god:
You are the lineal son of Air-god, and even by your gusting you are selfsame to Air-god, and even by your flying also you are his selfsame to Air-god, in all respects[.}
Hanumana was mischievous in his childhood, so some sages gave him a minor curse to forget his powers:
Apart from trying to snatch Sun-fruit, Hanuma's childhood-rascaling
was intolerable for some sages and hermits. Hanuma used to tease and
tickle the sages by snatching away their personal belongings, by
spoiling well arranged worship articles etc. Knowing that Hanuma is
indomitable by the blessings of Brahma and Indra and all the
celestials, and as a severe punishment is uncalled for, as he is
simple little monkey, the sages gave him a minor curse:
bādhase yatsamāśritya balamasmānplavaṅgama
taddīrghakālaṃ vettāsi nāsmākaṃ śāpamohitaḥ
yadā te smāryate kīrtistadā te vardhate balam [VR - 7.36.35 ]
Meaning
Deluded by this curse, for a long time you won't be able to remember your powers using which you caused us trouble. But when you'll be reminded of your glory, your powers will increase.
If Hanuma were to be aware of
his own might, the course of Ramayana would have been otherwise. He
would have simply enlarged his body and brought whole of Lanka island
to Rama, as he has lifted sanjivini mountain, to enliven Lakshmana in
the war with Ravana's son, Indrajit. So this was a necessary curse
upon Hanuma. Hence Jambavanta had to harangue Hanuma.
Regarding his flying, I have also heard the same. But he was son of wind god. So it must not be impossible for him to fly. The reference site mentions fly jumpers when translating the word plavangamāḥ and uses the word plavana to describe Hanuman's movement in the sky. So by using the word plavana, it would mean Hanuman was flowing in the sky, which just means He was flying.
@jabahar That quote isn't actually from the Kishkindha Kanda, just a note from the website author. Do you know whether that story comes from some actual scrpture?
@KeshavSrinivasan Yes, I am aware of that. So I have not mentioned anywhere in the answer the verse number or stated it's from Kishkindha Kand. I have only given the reference where I found it and where the description of Hanuman's flying and jumping ability has been mentioned.
Lord Hanuman was able to fly from birth, which is a gift given by his father Vayu Deva. You can notice this point when he first was tempted to eat the sun and flew to it.
But as he grew up, (as all kids do) he started to enjoy his childhood by troubling other saints, rushi (muni) with his extreme powers. So just to stay safe, rushis gave him Shaap to forget all his powers. Since Lord Hanuman was born for a reason, if he forgot all his powers, then the reason for which he was born would not be fulfilled. So as an alternate for that Shaap, rushis also said that in time of need, if someone reminded him that he has powers, he will get his powers back.
I have also heard that lord Hanuman was actually not able to fly but to jump to higher distances. Is it true?
This fly/jump is a knowledge which is given by his father Vayu Deva. When he was kid, he made his first fly/jump.
Apart from Hanuman, all Vanaras were able to fly. But they have their own capacity or limits to reach. At the time of flying to Lanka, Hanuman was not considered as first priority. Sugreeva asked others first like, Angada, Jambavanta and so on, but all others weren't able to fly that far.
Jambavanta considered to be elder among all have strength to fly for any distance, because he is old and less strength, he willingly suggested Hanuman to fly that far. Another reason may be because of Hanumans's birth reason, he is born to serve Lord Rama. So any work that belongs to Rama, Hanuman will do it.
Flying of Hanuman is also illustrated in one more situation. After the victory of Rama, (some part I excluded here) Rama gave a white lotus flower to Hanuman and told him to give it to Surya Deva on behalf of Rama. Hanuman flew to Surya Loka and gave that flower to Surya Deva. In this case, there is no Yojanas count, because he flew in outer space restlessly.
Like any library, Hinduism Stack Exchange shares great information, but does not offer personalized advice, and does not take the place of seeking such advice from any Acharya, Pundit, astrologer, Guru or other trustworthy Counselor.