Yes, Allah is always just and yes, He is sometimes merciful and forgives us for the sins we commit. This is not contradictory and here is why:
1. Quran 4:40 mentions that Allah will not wrong anyone in the slightest.
2. Quran 4:64 mentions that Allah is merciful to those who repent.
3. Showing mercy and forgiveness is not wronging someone. Rather it is withholding retribution.
Prophet Muhammad (peace be upon him) quoted Allah as saying, "My mercy prevails over My wrath" and "O My servants, indeed I have forbidden oppression upon Myself and I have also made it forbidden amongst yourselves, hence to not oppress each other".
A vivid example of oppression/injustice is to be found in the concept of original sin:
1. Adam (peace be upon him) committed a sin and was not only not forgiven for it, but all of his offspring were cursed with the burden of that sin which they did not commit, regardless of their piety or wickedness, and barred from entry into Paradise.
2. Jesus (peace be upon him), who was a sinless Prophet (Luke 13:33, Matthew 21:11) and unwilling participant (Matthew 26:39), was allegedly sacrificed for the sins of others.