As I see it, the law is quite clear on who gets the caution here. The trickery is by (and the caution is for) the player who uses a deliberate trick to contrive a situation whereby the the foot does not have to be used to pass the ball to the keeper. In this case, it is the goalkeeper who has committed the offence (when he flicks the ball up to the defender's head, not when he handles the ball). A keeper handling a ball that is headed to him is not committing an offence. Also, the defender has not committed an offence; heading a ball that arrives at you at head height, when you did not use a deliberate trick to get it there, is not an offence.
Don't forget, when FIFA Circular 488 was issued, the IFAB gave us examples of what constitutes a deliberate trick, one of which was, "a player who deliberately flicks the ball [up] with his feet ..." Now at that time, the scenario of one player flicking the ball up to another had not been put into the law (that came later) but flicking the ball up, whether to yourself or another player is clearly what breaches the intent of the law, not heading it after it's been flicked up.
The player who flicked the ball up is the goalkeeper, so for me, he is the one who has committed the offence of using a deliberate trick here.