Why did God punish communities who rejected their prophets?

Each answer is quoted as it is from the commentary of the Quran, with the passage it comes from.