Scotland’s top civil servant will leave the post next year, the Scottish Government has announced.