If my teacher is posting photos of questions given in a book in our class group for us to solve, is it legal or ethical?
The question is a bit subtle and requires interpretation. It depends on how much is "posted" and where and why it is posted. Copyright is a matter of civil law (most places), though the law varies. If you do an online search for "fair use for education" you will see some of the subtitles.
Republishing copyrighted material is a violation in many cases and does not require doing so for profit. Nor does it require that you somehow acquired the material improperly. If you republish all of the exercises in some textbook you will likely get sued if the copyright owner objects. The question is whether what you distribute to students can be considered republishing, but putting it on a public facing web site almost certainly is.
Small amounts from a copyrighted text are probably fine (probably). But one of the important questions in interpreting fair use is whether the republishing reduces the value of the work to the copyright holder. For some books the exercises are one of the most important and valuable elements. One or two exercises is probably fine. All the exercises is definitely not so fine, though the copyright owner needs to object (most jurisdictions).
Distributing small amounts privately to students (i.e. not a public facing site) are probably fine. But if the intent is to let hundreds of students avoid purchasing the book, then not so fine, perhaps.
The idea behind copyright is to let creators profit from their creations. If you attack that right in significant ways you can have problems. Originally the right was for a limited time, but that is changing, making the question more contentious. The secondary purpose was to encourage creators to contribute to the common good. Unlimited copyright goes against that idea and is one of the reasons for fair-use exemptions for such things as education, research, and (literary) criticism...