Donald Trump has told members of his cabinet that Elon Musk will leave his government role in the coming months.