ذَٰلِكَ أَن لَّمْ يَكُن رَّبُّكَ مُهْلِكَ ٱلْقُرَىٰ بِظُلْمٍۢ وَأَهْلُهَا غَٰفِلُونَ
That is because your Lord would not destroy the cities for wrongdoing while their people were unaware.
The reason for sending messengers to mankind and jinn is so that no one is punished for the crimes they committed without a messenger having been sent to warn them and the invitation reaching them. I only punished a nation after sending messengers to them.