I think I read this last year (2019) on the Kindle. I originally thought it was a Kindle Unlimited (they gave me a free trial) book, but I'm not seeing it on the list of books I checked out. The framing story is that a therapist (psychologist? researcher?) is attempting a radical therapy for a troubled youth where he's placed into a virtual reality scenario with his identity overwritten as a kobold or goblin (or maybe something else... but a lower race, generally considered to be evil) wherein he is offered a chance to level up to a character class. After considering the possibilities, he winds up selecting being a paladin, a very unusual choice in that when he uses his divine powers, he tends to suffer pain and damage since the system considers him evil. Morality is on a D&D spectrum of good versus evil, and law versus chaos, with it being a numerical spectrum. He gradually makes his way up towards good (hampered by the system penalizing him for things he sees as normal or even virtuous, like cannibalizing dead sentient beings), but keeps getting thrust further into chaos because he's acting in a way contradictory to his species.
Plotwise, I remember he runs into a priestess of some sort early on, who doesn't believe that he is a paladin, but nonetheless feels obliged to help him. He winds up at a refugee camp of some sort (I think one he's traded with before, run by some sort of fallen elf. He's convicted of a crime (I forget whether he was actually guilty of it), and is sentenced to death by being thrown into a pit of dire wolves. Due to his small size, he's able to cram himself inside of a crevice in the wall. In the pit, he befriends a runt dire wolf, which becomes bonded to him, and he eventually escapes. After escaping, he comes upon the scouts of an invading army and manages to survive the encounter, and he comes back to warn the camp. They manage to fend off the invaders due to a combination of setting traps and doing a fighting retreat, although it's very close. As I recall it, he does something which makes the priestess despise him, but he's satisfied because it was necessary to save the camp, and he feels loyalty to them now.
A recurring thread in the plot is him recalling some sort of "goblin laws" passed on to him by his mother that boil down to that the world is a cruel place where everyone is against you, so you have to take everything you can and fight unfair, and you'll still probably lose.
The context story about him being part of experimental therapy plays out in short vignettes where the researcher tries to justify the cost of the research to the board, and said board decides to defund the project, even though it will lead to the death (maybe just brain death?) of the boy because he's too deeply immersed in the simulation. In protest, the researcher herself enters the simulation, forcing them to consider two lives in the balance, one of which they have a financial investment in.
That's where I remember the story ending, providing a hook to a sequel.