Legislation that will see Scotland move to using five-year carbon budgets to set climate targets has been passed.