Because he plays in a position that tends to have a lot of yellows, quite a few of them "take one for the team" to stop a counterattack, and he's played the third most premier league games.
https://en.m.wikipedia.org/wiki/List_of_Premier_League_players_with_500_or_more_appearances
That isn't to say that he doesn't pick up some stupid cards, either by being a bit slow to the tackle or a bit rash, but it is less than you'd think, he's had 5 yellow cards this season which includes the two in one game that saw him sent off.
In comparison McCarthy, who has had almost half the game time has 4 whilst Matic has 8 despite still playing less than Barry. Not going to be many DMs who have played regularly that don't have a few yellows/reds to their name at this point in the season.