The Absence of the Hoopoe
Mujahid, Sa`id bin Jubayr and others narrated from Ibn `Abbas and others that the hoopoe was an expert who used to show Sulayman where water was if he was out in open land and needed water. The hoopoe would look for water for him in the various strata of the earth, just as a man looks at things on the surface of the earth, and he would know just how far below the surface the water was. When the hoopoe showed him where the water was, Sulayman would command the Jinn to dig in that place until they brought water from the depths of the earth. One day Sulayman went to some open land and checked on the birds, but he could not see the hoopoe.
Continue reading the tafsir of ayahs 20–21Ma'arif al-Qur'an
Mufti Muhammad Shafi
لَأُعَذِّبَنَّهُ عَذَابًا شَدِيدًا أَوْ لَأَذْبَحَنَّهُ
I will punish him with a severe punishment - 27:21
It is part of the political sagacity to punish the absentee after making due scrutiny.
It is permissible to punish a lethargic animal moderately
Allah Ta’ ala had permitted Sayyidna Sulaiman (علیہ السلام) to punish the animals in the same way, as He had permitted people of all ages, a permission which is still valid, to slaughter them to make use of their flesh, bones, skin etc. Similarly, if the domestic animals, such as cow, horse, camel, donkey etc., do not perform their normal duty, then it is permissible even now to punish them moderately for disciplining. Punishing animals, other than domestic, is not permissible under Islamic law. (Qurtubi)
أَوْ لَيَأْتِيَنِّي بِسُلْطَانٍ مُّبِينٍ
Unless he brings to me a clear plea. - 27:21
That is, if the hoopoe offers a plausible excuse for its absence, then it will be saved from the punishment. There is a subtle hint in it that it is expected of a ruler or an administrator that if someone falters doing something, then it should be thoroughly investigated before punishing him. The punishment should be enforced only when the guilt is established, otherwise he should be forgiven.
In Solomon’s army there were not only human beings but also genies and birds. Once Solomon’s army passed through a valley where there was a large number of ants. On this occasion Solomon understood what the ants were saying to each other. Such an incident would be enough to give rise to conceit and pride in an ordinary man. But, Solomon became the embodiment of gratitude on this account. He fully attributed to God whatever appeared to be his—and this is the way of a pious and righteous man.
Uthmani text of the Madinah mushaf (King Fahd Complex). Translation: Saheeh International. Tafsir via Quran.com.