Scotland’s former first minister has accused Elon Musk of accessing his private messages as part of a campaign to “besmirch” his reputation.