It is not quite easy to work out Anselm's position. But we can clear the ground a little.
In Anselm's Christian terms, the sinner acts unjustly towards God because the sinner does not 'give God what us owed to him' - righteousness, uprightness, obedience. (B. Davies & G.R. Evans, Anselm of Canterbury : The Major Works, Oxford : OUP, 1998, 283 - quote from Cur Deus Homo, §11.).
If God decided to condemn the sinner to eternal Hell for the least offence then Anselm's point would appear to be that, since 'God is subject to no law' (Davies & Evans, 284; cf. 285), this would not be unjust :
'If it is God's will that it would rain, then it is a just thing that it should rain; and if it is his will that some man should be killed [or condemned to eternal Hell - GT], then it is just that he should be killed [or condemned to eternal Hell]' (Davies & Evans, 286 : Cur Deus Homo, §12.)
Anselm's conclusion about the justness of eternal punishment might appear to exceed his premises, however. The central idea in his theory of justice is that if God did not punish the sinner then sin would be unregulated : and 'it is not fitting for God to allow anything in his kingdom to slip by unregulated' (Davies & Evans, 284.)
It does not follow that such regulation requires eternal punishment rather than some lesser retribution, one might say. But this only goes through if we forget that 'God is subject to no law' and so cannot act disproportionately.
The only light in Anselm's dark picture is that God is merciful (Davies & Evans, 91 : Proslogion, §9). If God decides to spare the sinner this also is just (ibid.) and, a crucial point, God is merciful and will forgive totally and remove from the scope of any punishment or retribution the sinner who 'turns from his wickedness and does what is right' (Ezek. 18: 27). (Davies & Evans, 304 : Cur Deus Homo, §20.)