When internet infrastructure was much less advanced, the server application used to be part of the delivered product so you could host it yourself at a LAN party.
I understand that packaging, documenting and supporting an additional application is a cost that the company would rather avoid if possible. But upon shutting down a game's servers, it would cost them nothing to provide the discontinued app code "as is" with no warranty or support, to let fans figure out how to run or improve it themselves. I doubt most game companies have any incredibly valuable and cutting-edge networking code worth protecting.
Middleware with limited licenses is also a problem the developer chose. If there was a legal requirement to publish the code (source code escrow should be required for copyright to be enforceable IMO) then developers would take care not to fall into that trap.
I understand that packaging, documenting and supporting an additional application is a cost that the company would rather avoid if possible. But upon shutting down a game's servers, it would cost them nothing to provide the discontinued app code "as is" with no warranty or support, to let fans figure out how to run or improve it themselves. I doubt most game companies have any incredibly valuable and cutting-edge networking code worth protecting.