Why some fouls lead to free throws.
In the NBA, a missed two-point shot with a shooting foul normally brings two free throws; a missed three brings three. If the basket counts, one additional free throw is normally awarded. Team-foul penalties can also produce free throws on non-shooting defensive fouls. Offensive fouls have different consequences.
A foul is not a violation.
NBA players normally foul out on their sixth personal foul. Traveling is a violation, not an extra personal foul. Unnecessary contact can be flagrant; unnecessary and excessive contact can be flagrant 2, with ejection. These are NBA categories and should not be transferred automatically to another league.
Follow the whole decision.
When watching a replay, note whether a shot had started, whether it went in and what the referee awards next. A free throw alone does not tell you which foul occurred.