https://en.m.wikipedia.org/wiki/Pendleton_Civil_Service_Refo...
So remember, when Trump talks about the "deep state," he means workers hired through a merit system.
People couldn't agree what merit was, and sued over it. Now it's not only [still] unclear what merit is, but it's also unclear how aligned federal hiring practices are with any platonic ideal of "merit".
Trump and Elon taking a blowtorch to a lot of agencies isn't better, or even good. It looks to me like a different kind of bad that can't be quantified at the moment. Some of the worst of this will be temporary, since various resources are offline so that federal agencies can be compliant with Trump's EOs while they figure out how to change the resources and their databases, or wait for lawsuits to clarify before changing much or putting it back online.
Hiring through a merit system does not imply that the employees' work is meritful.
Congress had over 140 years (1883 to 2024) to carefully balance the rights of civil service workers against the need for top-down executive authority to ensure agencies are effective, in a way that would survive judicial review. Unfortunately, Congress is inept at almost everything. The Pendleton Act, followed by the CSRA, don't seem to have very well addressed the original patronage-based exec-branch staffing issue; as the article describes it, they've only ensured that replacing high-level staff is delayed by a term. Have they also made it too difficult to dismiss lower-level staff if agencies are ever in need of scaling back?
All of this is happening within the Executive Office of the President, which is essentially fancyspeak to mean the government employees working the Executive Branch of the federal government. Those government employees serve at the pleasure of the President; Congress only has very limited influence (namely budgetary influences from the House and certain positions that require Senate confirmation).
So Musk, being appointed as a part of the Executive Branch, derives authority vested in the President of which Trump has delegated some to Musk for the purposes of implementing and enforcing DOGE policies.
Musk for his part also serves at the pleasure of the President, so whatever he does is ostensibly what Trump wants regardless of who actually does it.