Fouls Can Be Costly
Hacking generally is discouraged because it's not good defense. In a league game, referees keep track of player's fouls, and someone who hacks a lot will foul out quickly. In an informal game of pickup basketball, where participants are responsible for officiating themselves, hacking can lead to arguments if players don't agree on whether the contact the defender made was enough to constitute a foul or not.
Hack to Win
Some teams use hacking as a strategy to produce an on-court advantage. Fouling an opposing player who's a poor free throw shooter late in games serves multiple purposes -- it stops the clock and hurts the other team's chances to score. This is particularly true when the player would otherwise be taking a high-percentage shot. Teams often take this approach when an opposing center or forward who doesn't shoot free throws well gets the ball near the basket -- it can be a safer option than giving up a dunk or easy layup.