Each league has a foul limit. This is the number of fouls a player must commit to be thrown out of a game, or foul out. To be in foul trouble, a player must be within 1 or 2 fouls of fouling out.
In the NCAA, games are 40 minutes long and a player will foul out if he accumulates 5 fouls. This means a player is in foul trouble if they have 3 or 4 fouls.
In the NBA, games are a bit longer: they are 48 minutes. Because the game is longer, players only foul out if they get 6 fouls. This means a player is in foul trouble if they have 4 or 5 fouls.
If a player is in foul trouble, the coach will likely pull them out of the game. If the player fouls out early in the game, they can't be used in the dying seconds of the game which are typically the most important. If there is not much time left in the game, the player may be left in.
A team can also be in foul trouble. Remember that there is a set number of fouls a team can get before their fouls result in shots for the other team. If the team is near this limit, the team is in foul trouble.