First contact was outside but there was further contact inside so this makes it a penalty. Think of it as playing advantage for a second to see what develops. In this case the attacker was brought down inside the box but he might have got passed and maybe even have scored. When this is no longer possible then a penalty is awarded. Lucas was inside the box, his foot makes first contact outside but then his knee catches the opponent's thigh on the line and brings him down.