Utilities and governments tend to have close relationships.
Governments want utilities to continue working at reasonable prices, so they regulate utilities heavily. In exchange, utilities get protection against competition. This is true in many countries.
Specifically around solar, there's a concept called "utility death spiral" where more and more people opt out of the grid, causing the grid to be unmaintainably expensive. This the dream that solar conpanies tell their investors.
Power companies would of course want protection from the utility death spiral, and can often get it.
Disconnection isn't always illegal. Another form this can take is "all houses have to pay a grid fee, whether or not they are connected".