Kim didn’t announce he will attack Guam. North Korea’s top military official announced they will test missiles by firing them into the ocean near Guam.
The most likely reason is to demonstrate that they can do it and are willing to, even though the United States (via presidential statements) and the international community (via UN Security Council resolutions) told them not to.
Issuing the threat makes Kim and the North Korean military look tough to domestic and international audiences, which serves Kim’s strategy of staying in power. Following through and launching does that as well — even more so — but comes with risks. The ideal for North Korea is to act as tough as possible without actually provoking foreign attack.