is this legal?

If anything that sewer hook up may be a code violation.
The clean out it’s connected to isn’t designed for that kind of hook up. If it is they should have some sort of permit for it.