If Congress appropriates a specific amount of money for a specific thing, the president has limited power to not spend the money.
But many cases, Congress doesn’t appropriate specific amounts of money for specific things. It appropriates a bunch of money and gives it to agencies and department. That leaves the president with a lot of discretion in how and whether to spend the money.
It doesn’t help that Congress has been operating under continuing resolutions. That means Congress is shoveling money to the executive branch but hasn’t enacted former appropriations bills for many things.
As to why Musk can do it. Treasury is a department, not even an independent agency. The president runs it, along with the president’s appointee the secretary of treasury. DOGE is an office within the Executive Office of the President. The President can just create offices for executive managers, like Obama did to appoint the first Chief Technology Officer: https://www.theregister.com/2009/04/20/aneesh_chopra_us_cto/.