MSPs have approved wide-ranging legislation proposed by the Scottish Government to reform how the justice system operates.