There are quite a few rules that matter here, but the TL;DR is that it's legal to touch the facemark of the opponent, so long as it's not:
- Strike, Club, Swing, Thrust (a "forceful hit")
- Grasp, twist, pull
In the first picture, I suspect that he probably is committing a foul, but it's probably hard to see and be confident he's actually grabbing (and we'd need the video to know). Referees are a dozen yards away probably at this point, so they have a very limited ability to police things on the edge here; sometimes they see it, sometimes they don't.
In the second picture, that's probably legal contact, if he extended his arm prior to the contact. It wouldn't be legal if he started the contact with a very bent arm and then thrust away the player by the helmet (that would qualify as a "thrust", or a "forceful hit"). But this kind of contact happens all the time; stiffarm to the facemark is okay if it's just a "keep your distance" stiffarm and not something more forceful, and as long as there is no closing of the fingers (grasping/pulling/twisting).
The various fouls that can be called in this area are all over the rulebook, but a few examples:
Rule 12.1.3, related to blocking:
It is a foul if an offensive blocker:
Thrusts his hands forward above the frame of an opponent to forcibly contact him on the head, neck, or face;
Note: Contact in close-line play is not a foul, unless it is direct and forcible, or prolonged.
Rule 12.1.7, related to defensive use of the hands:
It is a foul if a defensive player thrusts his hands or arms forward above the frame of an opponent to forcibly contact him on the neck, face, or head.
Note: Contact in close-line play is not a foul, unless it is direct and forcible, or prolonged.
Plus 12.2.15 on facemasking (the personal foul variety), and various other smaller points.