The first sentence has two possible meanings, depending on where you put the punctuation. “It was God, punishing the people who did bad things.” This could be said in response to, say an earthquake or plague. The speaker would be saying - it (the bad thing that happened) was a punishment from God. If the sentence is said without the comma and an emphasis on GOD, then it means the same as the second sentence. It was God that was punishing the people (as opposed to any other entity).
I don't know if that answers your question??