I believe there are penalties that once accepted automatically yield a first down. And there are others that don't always result in a first down, put depending on the location of the foul (regarding to the line of scrimmage) will yield a first down. So when does a penalty results in a first down?
I assume you're asking about penalties committed by the defending team. In general terms, a penalty results in a first down when:
The penalty always results in an automatic first down.
The penalty yardage is sufficient for the offense to reach the line to gain. For example, a five yard penalty committed by a defending team when the offense requires five yards or less.
This is what the NFL 2017 rules say for penalties committed by the defense ("Team B") (emphasis mine):
Item 5. Foul by Team B. After a penalty for a foul by Team B prior to (between downs) or during a play from scrimmage, the ensuing down is first-and-10 for Team A.
Neutral zone infraction
Delay of game
Excess time out
Running into the kicker
More than 11 players on the field at the snap
More than 11 players in the formation prior to the snap
Illegal formation by the defense during a scrimmage kick play
For the above exceptions, the number of the down and the line to gain remain the same unless a distance penalty places the ball on or in advance of the line to gain, in which case it is first-and-10 for Team A.
Slightly unhelpfully, when the Rulebook says that it does. For example, illegal contact by the defense (Rule 8, Section 4, Article 1) results in:
Penalty: For illegal contact by the defense: Loss of five yards and automatic first down
(my emphasis) However, some other fouls do not result in an automatic first down. For example, an illegal punt formation by the defense (Rule 9, Section 1, Article 3, Item 2) results in:
Penalty: For illegal formation by the defense: Loss of five yards.
but with no automatic first down.