Bonuses are paid out by the team who has him on the roster when it's due.
Bonuses (of all kinds, usually roster and signing bonuses) then hit the cap divided by the number of years remaining in the deal. A 5 year $5m contract, with $5m signing bonus, would count for $2m/year on the cap ($1m/year salary, $1m/year hit from signing bonus). I am pretty sure if that player is released before the end if their contract then the team's cap will be hit for $1m/year for the rest of it's duration because they received the cap benefit for the years the player was on the team.
Often times teams restructure to free up cap room.
In the above example, the player is hitting the cap for $2m/year. On year 3, he could restructure, take a $600k bonus payout and reduce his salary to $400k, now his cap number year 3 is $1.6m ($1m from signing bonus, $400k salary, $200k prorated bonus cap hit) instead of $2m, but that inflates the subsequent years, which would now be $2.2m.
That's not a lot of savings, but add a zero to all of the numbers and you just saved $4m in cap room. Often restructuring is more complex, years are added, etc.
Was going to make a chart or something, but if you're really that interested I think you can figure it out from the above