There are some computer and math books produced for university courses placed on the internet pages of those courses. These books or lecture notes are then formally published and removed from the course webpage, but a copy can be found either on archive.org or some other site.
Is it legal or ethical to obtain the previously published pdf from archive.org or some other site? One example is "Algorithms" by S. Dasgupta, C.H. Papadimitriou, and U.V. Vazirani, which was previously available on Dasgupta's webpage but later taken offline when the book was published in paper form.
The other situation would be course notes that were publically accessible but later removed from the webpage but still available on archive.org.
In terms of ethics, if you felt compelled to ask then perhaps you should dig deeper, and in particular inquire with the authors about 1) how they intended to license the work, and 2) what their licensing arrangement was with the publishing house. It also couldn't hurt to inquire with whomever uploaded it to archive.org; perhaps they had permission from the authors. Neither answer would necessarily resolve the legal question, but might satisfactorily resolve your ethical qualms.