I believed that Pepe tried to get Muller sent off. Pepe struck his fingers into Muller face as act of frustration. Then Muller made most of it. As Muller on the ground it was much easier for Muller to headbutt Pepe. And maybe Pepe realised this. He put his head as near to Muller hoping the Germany would react by getting up. This would surely shown as Muller headbutted Pepe but that did not happen. Muller stayed on the ground and Pepe got carried out. He accidentally headbutted Muller. As the result Pepe was shown a red card.
See this accident between Ariel Ortega and Van Der Saar in World Cup 1998
Argentinian football player Ariel Ortega was sent off in the 1998 World Cup quarter final match between Argentina and Netherlands for headbutting Dutch goalkeeper Edwin Van Der Sar. Van Der Sar confronted him after a dive in the penalty area, for which Ortega was just getting his first yellow card. Argentina lost 2-1