All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger.
Indeed, animals do have a kind of discernment and perception and a Fitrah (natural disposition) which guides them to their benefits in life, but it is – undoubtedly – an inferior Fitrah compared to the Fitrah of a human being. Rather, it cannot be compared to it in principle. Therefore, the acts of animals cannot be described as either good or evil, or as sin or disobedience. Ar-Raazi said in al-Mahsool: “The third description (of the prohibited) is that it is a sin, which is what is forbidden and which necessitates punishment and accountability; it is for this reason that the acts of animals and children cannot be described as such, but an act of an adolescent can be described as such, as he is generally disciplined for his actions.”
As regards your question about how can Allaah allow this to happen, then the answer is that Allaah has the absolute freewill; the Dominion is His, and the Creation is His Creation, He creates whatever He wills and He chooses; Allaah says (what means): {His command is only when He intends a thing that He says to it, "Be," and it is.} [Quran 36:82]
Allaah has the absolute wisdom in His actions which may or may not be perceived by the human being. Shaykh Al-Islam Ibn Taymiyyah said: “Thus, everything Allaah does, we know that there is wisdom in it. This suffices for us in general even if we do not know the details. The fact that we do not know the details of His Wisdom is like not knowing about how His Essence is. His perfect Attributes are known to us, but how His Essence is, is not known to us. So, we believe what we do not know – i.e. the details of His Perfection – by virtue of what we do know about His Perfection. Also, we know that He is wise in His acts and in what He commands, and the fact that we do not know the wisdom in some matters, does not detract from what we know about the essence of His Wisdom.” [End of quote]
Finally, it should be pointed out that a Muslim should ask about matters that necessitate action and not about matters which if one knows them, it does not benefit him, and if he does not know them, it does not harm him.
Allaah Knows best.