The NBA salary cap is what's known as a soft cap. It limits the amount of money that teams can spend, but teams can exceed it if they are willing to concede certain penalties (usually monetary).
Some things that are worth mentioning here, with the lockout a few years ago, the NBA's salary cap structure changed. The two moves that you seem to be interested in (Dallas' dismantal and the Heat's collection) both happened under the old cap structure.
Salary caps are very complicated beasts (NBA wikipedia article here), but at their heart they say this:A specific portion of the league's revenue is set aside for player salaries, we'll divide that total by the number of teams and set that as the salary cap (with some wiggle room, probably down for teams going over). Usually there is also a salary floor which says that teams have to spend a certain amount of money on player salaries.
The NBA has additionally capped individual player salaries, a max contract player...