By UEFA rules the ref had to give the pen.
No, he didn't. These are the IFAB Laws of the Game regarding handball;
Handling the ball For the purposes of determining handball offences, the upper boundary of the arm is in line with the bottom of the armpit. Not every touch of a player’s hand/arm with the ball is an offence. It is an offence if a player:
• deliberately touches the ball with their hand/arm, for example moving the hand/arm towards the ball
• touches the ball with their hand/arm when it has made their body unnaturally bigger. A player is considered to have made their body unnaturally bigger when the position of their hand/arm is not a consequence of, or justifiable by, the player’s body movement for that specific situation. By having their hand/arm in such a position, the player takes a risk of their hand/arm being hit by the ball and being penalised
• scores in the opponents’ goal: • directly from their hand/arm, even if accidental, including by the goalkeeper
• immediately after the ball has touched their hand/arm, even if accidental
The goalkeeper has the same restrictions on handling the ball as any other player outside the penalty area. If the goalkeeper handles the ball inside their penalty area when not permitted to do so, an indirect free kick is awarded but there is no disciplinary sanction. However, if the offence is playing the ball a second time (with or without the hand/arm) after a restart before it touches another player, the goalkeeper must be sanctioned if the offence stops a promising attack or denies an opponent or the opposing team a goal or an obvious goal-scoring opportunity.
I can't find a written copy of UEFA's guidelines but at the end of last season they had a meeting to discuss clarification of various rules, one of these was the handball rule. Their press release afterwards stated that in the 23/24 season they stated that "• In their guidelines for the next season, the Board recommends that UEFA should clarify that no handball offence should be called on a player if the ball is previously deflected from his own body and, in particular, when the ball does not go towards the goal."
The referee was asked to take a look at it on the monitor for whatever reason (I'm guessing the clear and obvious thing doesn't apply consistently) then because the VAR guy decided that the defenders arm was in an unnatural position then he had to give it. The VAR guy either ignored or had a different interpretation of the part of the law that states "A player is considered to have made their body unnaturally bigger when the position of their hand/arm is not a consequence of, or justifiable by, the player’s body movement for that specific situation".
What has actually happened here is the referee made the right call, the VAR team decided to use the strictest, most narrow and incorrect view of the Law disregarding what it was originally written for and then the referee has felt under pressure to use the VAR version of the Laws.
The ref absolutely did not have to give that penalty under UEFA or anybody elses rules. He made the right decision then somebody else got involved and the wrong decision was made.