It isn't legal at all. These websites pirate anime episodes so that viewers who cannot access the episodes over legal streamers such as Funimation Now or Crunchyroll.