From an objective point of view, Pep stayed for another 2 years because the club don't know who to appoint next. Txiki was hired in his role, as the owners knew 2 things, 1. He could get Pep to the club as they're close friends, and 2. He could build a squad for Pep having done that before in the past. That makes the signing of the new deal after Viana has agreed even more unusual.
I know people won't want to hear this, but I think the owners would have wanted a similar model which would be - Hire Viana, Hire a Manager he's worked successfully with - Amorim. That can't happen for the time being, so Pep now has effectively become an interim in a new project. Is Pep Viana's man? Probably not as he was Txiki's man and Txiki is moving on. If Txiki's next club is right you can see Pep following him to wherever that is. The next decision is what is the sporting direction of the club? Again that was driven by Txiki and Pep and goes right through the first team down into the academy. What happens when Viana comes in? Does he continue what has been working even though it's not "his way", or does he try and implement "his way". If he does, then you could end up with a lack of synergy, and something of a clash of styles if Viana and Pep aren't on the same page. It also effects recruitment too. At some point as well for a smooth transition, players will need to be recruited for the next manager, and his style of play. That means Pep ends up with players that aren't his players as he knows he's leaving. Only way it goes smoothly is if the next manager has a very similar style of play to Pep or has worked with him. I think it ends up being Kompany, but he probably wants to commit to Bayern for longer than a year. From an outsiders point of view he'll win stuff in the next 2 years, but it just won't be as plain sailing.