Basketball rules state that in the event a player commits his 6th (or 5th foul, the number may vary) personal foul, he is automatically disqualified and can no longer play in the game. Disqualification for reaching the personal foul limit is not that uncommon in the basketball, and every time a player is fouled out, a substitute sitting in the bench comes in. However, this rule may raise the question, "Is it possible for an entire team to foul out?". Although it may sound unlikely, similar situations have happened before, and there are rules that stop a whole team from fouling out.
Rule 3, section I, of the NBA's official rulebook says that although committing six personal fouls disqualifies a player, a basketball team cannot be reduced to less than 5 players in any circumstance. The rulebook also says that all teams must have at least 8 players dressed to play, 5 starters and 3 bench players. However, in the event that all bench players have already been disqualified, or are unable to play for some reason, the player who last committed his 6th foul gets to stay in the game. But that also comes with a penalty, whenever that player commits another foul, his team will be charged with a technical, as well as with the usual team foul. So the answer to the question is no, it is not possible for an entire team to foul out of a basketball game.
Although it may seem impossible, a situation where a player with six personal fouls gets to remain on the court, it has happened multiple times in history. One example is during the last game of the 2010 NBA season between the Golden State Warriors and the Portland Trail Blazers. The Warriors only had six healthy players. However, two players fouled out, and with all the bench player being injured or disqualified, the last player to commit his 6th foul got to stay on the court and play the rest of the game. The Warriors eventually won with a superb effort from rookie Stephen Curry with 42 points, nine rebounds and eight assists.