I once taught a comparative religions class alongside a Muslim imam (I was presenting the Buddhist view), and this question emerged as a fundamental differing point. Islam places great emphasis on the ideal of justice, whereas Buddhists put compassion in that central position. At the time, I gave this a lot of consideration because I found it interesting that the word justice rarely surfaces in a Buddhist context, and compassion rarely gets mentioned in an Islamic context.
To my mind, Justice is inextricable from notions of right and wrong. There are a few things most people will agree to be right or wrong, but there is also a great deal of disagreement on other things. Social groups have gotten around this ambiguity by setting up an arbiter of right and wrong, whether that be Allah, Jesus, or the government. It’s not too surprising that a justice-centered system would tend to marginalize compassion, because compassion tends to muddy-up dichotomies like right and wrong.
To put compassion at the center, you have to be comfortable with ambiguity and lack of absolutes. The overriding consideration is the welfare of those involved, not the application of a standard. There are often no clear answers, so one just has to act from the “heart” (or not act at all). The notion of Justice can get in the way of this compassion-centered paradigm, because the dictates of justice sometimes outrage the sense of compassion.
Which is more fundamental? I’m not sure that’s the best way to frame the question. They’re based in different parts of the brain. Studies have demonstrated that non-human animals and very young children have a sense of fairness, which is a form of justice. Compassion seems to come online somewhat later. But they’re both right there in our makeup.
Which should have priority in our moral dealings? On an interpersonal level, I’d say compassion, hands down. On an institutional or societal level, I think justice has to hold the reins.