Not when you touch the ball first.
I've seen 100's of situations when two players go for the ball. One with his foot high and the other one with his head. When the guy with the high foot touches the ball, the ref gives a foul (and a yellow sometimes) to the guy with the high foot. It's a very dangerous play too and it targets the head. The yellow is given for dangerous play, but I'm yet to see a red card given for that.
Yesterday's situation was the same.
Now, the ref could have thought that it's a dangerous play and Pepe targeted the leg, without touching the ball at all, and he gave a red card for that. In any case, even if the ref didn't give the red to deliberately give advantage to Barca, he made a mistake.
But looking at other situations when Real were getting yellows for the things Barca wasn't carded, then it questions the red card decision too.