They lose money, they are a liability headache, they are a huge security problem. There's no law saying a hospital HAS to have an ER. I don't know why they all don't close.
Actually, there are many laws concerning that exact situation, right down to how many free beds must be available, especially if you accept any government money, eg, Medicare or Medicaid.