It resets 24 hours after you achieve the 5 stars, though some star gaining mentions do not pass.
In case the current Star Bonus isn't completed within 24 hours, a new one will be available immediately after the current Star Bonus has been completed. At most two Star Bonuses can stack at one time. However, in this case, some "Star Bonus Time" will be wasted.
Since the Star Bonus is deposited in the Treasury, you may protect the loot by NOT collecting the star bonus unless the resources are already near or over the amounts needed to reach the cap of the current Town Hall level. This is because only 3% of all loot in the treasury can be stolen.
Star Bonuses begin to contain Dark Elixir at Gold III, while League Bonuses begin to contain Dark Elixir at Crystal III. Also, the maximum Star Bonus is available starting at Titan III League, while the maximum League Bonus is obtained at Legend League. At Titan III or above, the Star Bonus contains less Dark Elixir than the League Bonus.
There have been several Star Bonus Events during which the Star Bonuses are increased by a factor.