We encounter an imprisoned goblin in our exploration of the keep, telling us he fell foul of the boss goblin's favour, which prompts a lengthy discussion on whether we should release him and let him accompany us. If he really is friendly after we release him then he can guide us through the keep and perhaps even steer us away from traps. But regardless of his intentions to his rescuers it could be in his nature to be hostile to adventurers and could instead lead us to an ambush despite the consequences.
Our warlock has the answer, with his 'detect enemy' ability. With a far more dramatic gesture than is necessary, he channels his magical energy and claims that he has 'cast a curse, affecting the closest enemy', before asking, 'is it you, goblin? There is only one way to find out!' And with that he launches all his most devastating spells in quick succession on the green fellow, eventually inflicting the single point of damage that kills the minion.
'A cursed enemy's death causes me to teleport. I did not teleport upon the goblin's death. That means he was not cursed and thus was not the nearest enemy. Goblin—my friend—you are free to accompany us on our adventure.'
Our problem of the goblin joining us is solved.