Simply, you can't. If it is an illegal website, the owners will not tell you that it is illegal. They will tell you it is legal. If it is legal website, the owners will tell you that it is legal. In the end, the only answer you can get is that it is legal.
What you can do is that instead of treating the website as a whole, treat the books individually. You can check whether they are in public domain or not, since an illegal website can have both kind of books. It comes down to trusting the websites or doing your homework about those books you are interested in.
If you download books from those sites, depending on your country, it can be illegal or not. Your country should have some laws about copyrights. Most likely, it is illegal because it is stealing.
If you have not commited any crime before, you usually don't go to jail but repetition of such crimes can result in jailtime, again depending on the country. However, there isn't any action on downloaders of digital properties in most of the countries. I know that Germany took action once on people that downloaded movies, but that was it. Countries, if they are going to bother, bother with owners of such websites. The possiblity of you being caught is infinitely small.
I should also probably note that illegal websites are very easy to notice. It shouldn't take more than a minute to clearly see that it is illegal. Websites with latest novels, or many coursebooks are surely illegal.
People who want to safely download digital properties for free usually use proxies or TOR to stay anonymous.