First let me address your last paragraph, hunting isn't per se haram, it is only haram to kill for people who wear Ihram (for any of both 'Omrah or hajj) which is quoted in the next verse:
O you who have believed, do not kill game while you are in the state of ihram. ... (5:95)
Therefore the test for the believers was that they had the opportunity to hunt, but they were wearing ihram, while Allah just told them it is forbidden to do so in that state.
an other verse which emphasize this prohibtion is the first vers of the same surah:
O you who have believed, fulfill [all] contracts. Lawful for you are the animals of grazing livestock except for that which is recited to you [in this Qur'an] - hunting not being permitted while you are in the state of ihram. ...
Back to verse (5:94) here a quote from a summary of tafssir ibn Kathir:
Ali bin Abi Talhah﴾Al-Walibi) said that Ibn 'Abbas said that Allah's statement,
(Allah will certainly make a trial for you with something in (the matter of) the game that is well within reach of your hands and your lances,)﴿5:94﴾,
refers to, "The weak and young game. Allah tests His servants with such game during their Ihram, that if they wish, they would be able to catch it with their hands.
Allah has commanded them to avoid catching it.'' Mujahid said that,
(well within reach of your hands)
refers to the young game and chicks, while
(and your lances,)
refers to mature game.
Muqatil bin Hayyan said that this Ayah was revealed during the 'Umrah of Al-Hudaybiyyah, when wild game and birds were coming to the Muslim camping area, which they had never seen the likes of before. Allah prohibited them from hunting the game while in the state of Ihram. (source qtafsir)
Imam al-Qurtobi his tafssir said that the Arabs used to hunt and one could say they were addicted to hunt, so Allah tested them as he tested the children of Israel on Saturday (see 7:163 and 2:65, 4:154 which refer to the former verse) by the revelation of the above verse (5:95). This is said to have happened on the year of al-Hudaybiyah, so some of the companions were wearing ihram while others were not, so they were unclear about rulings once they had the opportunity to hunt and Allah lifted what was unclear by telling them.
In his at-tahrir wa-tanwir sheikh ibn 'Ashur after saying that in his opinion this verse was only meant as an explanation of the first verse of the surah. He then also quotes the story of al-Hudaibiyah:
وقد روي عن مقاتل : أن المسلمين في عمرة الحديبية غشيهم صيد كثير في طريقهم ، فصار يترامى على رحالهم وخيامهم ، فمنهم المحل ومنهم المحرم ، وكانوا يقدرون على أخذه بالأيدي ، وصيد بعضه بالرماح ، ولم يكونوا رأوا الصيد كذلك قط ، فاختلفت أحوالهم في الإقدام على إمساكه ، فمنهم من أخذ بيده وطعن برمحه . فنزلت هذه الآية اهـ
(My own -partial and free- translation take it carefully)
A it was narrated from Moqatil that the Muslims on the 'Omrah ('umrah) of al-Hudaibiyah have been literarily covered by hunting game ... so that some of them started to throw their spears and lances, -while some were wearing ihram and others not- and they were even able to catch by hands, and they never experienced such a situation, so that they were uncertain on the ruling and what to do, some caught by hand and killed with a lance and some were uncertain whether they should leave the game, then this verse was revealed ...
Ibn 'Ashur then added that it seems like this verse was added to this surah to remind them on the year of hajjat al-wad'a to not fall in the same mistake again. Because on that year there were a lot of Muslims and many new converts from Arabic tribes who would perform hajj.