When Allah asked the angels to prostrate before Adam (AS) then Iblis refused. How did he deny the command directly given by Allah (swt) knowing that Allah (swt) is Almighty and that His punishment will be severe?
He had the choice to sin or not. Some beings are stubborn and arrogant. We see this with humans as well that they know the truth of Allahs punishment yet still persist in sin knowingly.