This is just a simple example of a general vs. specific ayah. It is not a contradiction, but rather one is making a general statement and the other is looking at a specific case exception.
For example, if I say the following two statements:
It is not necessarily a contradiction. In the first I am saying a general statement about the wall, and in the second I am looking at a specific part of it. Likewise when Allah says:
This is not a contradiction. In the first, Allah is saying a general statement which is true. No one will be punished for the sins of another. But, there is an exception, where people do get punished for another's sins if they were responsible for causing them to do it.
There is another example of a similar case in the Quran:
But whoever kills a believer intentionally - his recompense is Hell, wherein he will abide eternally, and Allah has become angry with him and has cursed him and has prepared for him a great punishment. (4:93)
and
Because of that We ordained for the Children of Israel that if anyone killed a person not in retaliation of murder, or (and) to spread mischief in the land - it would be as if he killed all mankind, and if anyone saved a life, it would be as if he saved the life of all mankind. And indeed, there came to them Our Messengers with clear proofs, evidences, and signs, even then after that many of them continued to exceed the limits (e.g. by doing oppression unjustly and exceeding beyond the limits set by Allah by committing the major sins) in the land!.
In the first ayah, Allah makes a general statement that killing a Muslim is a thing that you will be punished in Hell for. But, in the second ayah an exception is given (murder and corruption). One is a general statement and the other is a specific case exception.